2

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.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.

4 Answers 4

13

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Unbelievable it works like a charm. Thanks in advance!
3

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 the name property

Comments

2

You are missing SELECT in your query.

query="SELECT e FROM ElaborazionePagamentiMaggioriOneri e  WHERE

1 Comment

The missing SELECT e is valid Hibernate syntax.
1

In addition to missing SELECT, the "is not mapped" error is probably because you don't have the class registered in persistence.xml.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.