Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Hibernate's JPA throws Invalid Identifier error

843859Sep 20 2007 — edited Nov 20 2014
Hi folks,

I have multiple JPA entities and some are annotated with NamedQueries. When the program executes, the provider finds all those namedqueries just fine. But when it's time to execute one, hibernate complains that one of the fields in my named query is trying to reference an invalid identifier. For example:
@Entity
@Table(name = "CONCEPT_MGT_REL")
@IdClass(ConceptMgtRelId.class)
@NamedQueries ({@NamedQuery(name="testYou", query="Select mro.conceptDef1, mro.conceptDef2 from ConceptMgtRel as mro where mro.link= :myLink )})
public class ConceptMgtRel implements Serializable
{
     

     @ID
     @Column(name= "CONCEPT_DEF1")
     public String conceptDef1;

     @ID
     @Column(name= "CONCEPT_DEF2")
     public String conceptDef2;

     @ID
     @Column(name= "LINK")
     public String link;
}

//Client Code
public class Client
{
     public List<Object[]> getMyConceptsByLink(String linkId)
     {
          List<Object[]> = jpaEntityManager.createNamedQuery("testYou").setParameter("myLink", linkId).getResultList();
     }
}
So when I run that, I get the following error at the query execution line:

2:20:37,452 WARN JDBCExceptionReporter:77 - SQL Error: 904, SQLState: 42000
12:20:37,453 ERROR JDBCExceptionReporter:78 - ORA-00904: "*CONCEPTMGT1_*"."LINK": invalid identifier

First I'd imagine hibernate would alias the table similar to how it's spelled note how in bold. I'd expect it to start with smthg like *CONCEPTMGTREL* instead of *CONCEPTMGT*.
Second, there actually is another entity class named ConceptMgt , +not ConceptMgtRel+, mapping to the table CONCEPT_MGT. When I run named queries on that entity, everything works fine and i can see from the logs that the table alias for that entity begins with *CONCEPTMGT* .
Third, the attribute "LINK" is an attribute of the table CONCEPT_MGT_REL so I dont understand why it thinks that it's a invalid identifier.
I dont know if while parsing the named queries accross similarly named entities Hibernate messes up and wrongly binds queries to their entity or smthg screwy like that. I just cant explain or know where to begin as I looked at every detail in the configuration of the entities with their named queries.

I have read somewhere that the entities may not be in sync with the schema. But I just cant drop the schema as I'm not the only engineer working with it. So I renamed my entity ConceptMgtRel to ConceptMgtRl in hopes that Hibernate would have to map a whole new entity to the schema's table. But that didnt help.

If anyone has ran into a similar issue, it would greatly be appreciated to read your advice, comments, suggestions.
Thanks much all
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 18 2007
Added on Sep 20 2007
0 comments
1,541 views