JPA: Errors in named query
Solution 1
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.
Solution 2
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:
- 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
Solution 3
You are missing SELECT
in your query.
query="SELECT e FROM ElaborazionePagamentiMaggioriOneri e WHERE
Solution 4
In addition to missing SELECT, the "is not mapped" error is probably because you don't have the class registered in persistence.xml.
Vitaly Olegovitch
Data Engineer, theoretical computer science enthusiast
Updated on March 22, 2020Comments
-
Vitaly Olegovitch about 4 years
I get the exception
org.hibernate.HibernateException: Errors in named queries: ElaborazionePagamentiMaggioriOneri.estrai
but the named query looks correct to me. I also getorg.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.