Java JPA:命名查询中的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23656332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JPA: Errors in named query
提问by Виталий Олегович
I get the exception org.hibernate.HibernateException: Errors in named queries: ElaborazionePagamentiMaggioriOneri.estrai
but the named query looks correct to me. I also get
我收到异常,org.hibernate.HibernateException: Errors in named queries: ElaborazionePagamentiMaggioriOneri.estrai
但命名查询对我来说是正确的。我也得到
org.hibernate.hql.ast.QuerySyntaxException: ElaborazionePagamentiMaggioriOneri is not mapped [FROM ElaborazionePagamentiMaggioriOneri e WHERE e.dataInizioLancio IS NULL AND e.dataFineLancio IS NULL AND e.distinta IS NULL]
My entity is the following:
我的实体如下:
@Entity(name="ELABORAZIONE_PAGAMENTI")
@Table(name="ELABORAZIONE_PAGAMENTI")
@NamedQuery(name="ElaborazionePagamentiMaggioriOneri.estrai",
query="FROM ElaborazionePagamentiMaggioriOneri e WHERE e.dataInizioLancio IS NULL AND e.dataFineLancio IS NULL AND e.distinta IS NULL")
public class ElaborazionePagamentiMaggioriOneri {
@Id
@GeneratedValue
@Column(name="ID_ELABORAZIONE")
private long idElaborazione;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_INTERVALLO")
private Intervallo intervallo;
@Column(name="IMPORTO_MINIMO")
private BigDecimal importoMinimo;
@Column(name="IMPORTO_MASSIMO")
private BigDecimal importoMassimo;
@Column(name="LIMITE_DISPOSIZIONI")
private Long limiteDisposizioni;
@Column(name="DATA_INIZIO_LANCIO")
private Calendar dataInizioLancio;
@Column(name="DATA_FINE_LANCIO")
private Calendar dataFineLancio;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_DISTINTA")
private DistintaMaggioriOneri distinta;
What is the origin of the error? I have double checked the JPQL syntax.
错误的根源是什么?我已经仔细检查了 JPQL 语法。
采纳答案by Karibasappa G C
Entity name
used with @Entity
and the name of the entity you are using inside Select query should be same, if you are not using entity name with @Entity
then class name should be used with the Select query. Check this properly.
Entity name
used with@Entity
和您在 Select 查询中使用的实体的名称应该相同,如果您不使用实体名称 with@Entity
那么类名应该与 Select 查询一起使用。正确检查这一点。
回答by A. Agarwal
You are missing SELECT
in your query.
您SELECT
的查询中缺少您。
query="SELECT e FROM ElaborazionePagamentiMaggioriOneri e WHERE
回答by tzimnoch
In addition to missing SELECT, the "is not mapped" error is probably because you don't have the class registered in persistence.xml.
除了缺少 SELECT 之外,“未映射”错误可能是因为您没有在 persistence.xml 中注册该类。
回答by Виталий Олегович
The problem is that if you put the annotation @Entity(name="ELABORAZIONE_PAGAMENTI")
you set the name of the entity to be ELABORAZIONE_PAGAMENTI.
There are two solutions:
问题是,如果您放置注释,@Entity(name="ELABORAZIONE_PAGAMENTI")
您将实体的名称设置为 ELABORAZIONE_PAGAMENTI。有两种解决方案:
- modify the named query into
FROM ELABORAZIONE_PAGAMENTI e WHERE e.dataInizioLancio IS NULL AND e.dataFineLancio IS NULL AND e.distinta IS NULL
- modify the
@Entity
annotation by removing thename
property
- 将命名查询修改为
FROM ELABORAZIONE_PAGAMENTI e WHERE e.dataInizioLancio IS NULL AND e.dataFineLancio IS NULL AND e.distinta IS NULL
@Entity
通过删除name
属性来修改注释