-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Criteria Query with EmbeddedId -> "Unknown Column" Error
PostPosted: Tue Sep 21, 2010 1:02 pm 
Newbie

Joined: Tue Sep 21, 2010 12:43 pm
Posts: 6
Hello!

I would be pleased if you could help me with an issue that seems quite strange to me. I'm new to Hibernate, so please excuse me if it is a dumb question.


I have the Java classes "PropertyNameEntity" and "PropertyValueEntity".
The class "PropertyValueEntity" has an EmbeddedId referencing a class called "PropertyValuePK". This EmbeddedId class contains a ManyToOne Association to the class "PropertyNameEntity".

Everything is working fine, but a problem arises when I want to execute the following Hibernate Criteria Query:
Code:
crit = session
        .createCriteria(PropertyValueEntity.class)
        .createCriteria("propertyValuePK")
        .createCriteria("propertyNameEntity")
           .add(Restrictions.like("name", "GSM"));


I get the following error:
Code:
WARNUNG: SQL Error: 1054, SQLState: 42S22
21.09.2010 18:41:17 org.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Unknown column 'propertyna2_.name' in 'where clause'
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query


The "createCriteria" statements are working. The error only arises when I add the "Restriction" to the criteria.


Thank u for any information!


Top
 Profile  
 
 Post subject: Re: Criteria Query with EmbeddedId -> "Unknown Column" Error
PostPosted: Wed Sep 22, 2010 7:43 am 
Newbie

Joined: Tue Sep 21, 2010 12:43 pm
Posts: 6
I still have no idea how to solve this problem. I tried the same query in HQL, and this is working:

Code:
from PropertyValueEntity where propertyValuePK.propertyNameEntity.name like 'GSM'



But no progress with the Criteria query. I've already tried setFetchMode and createAlias, but nothings working.

I've set the "show_sql" property to true, which shows, that the following SQL is produced from the Criteria Query:

Code:
Hibernate: /* criteria query */ select this_.artikelId as artikelId8_0_, this_.eigenschaftsNameId as eigensch3_8_0_, this_.eigenschaftsWert as eigensch2_8_0_ from haym_info.eigenschaftswert this_ where propertyna2_.name=?


Why the Criteria query does not result in a Join?


Top
 Profile  
 
 Post subject: Re: Criteria Query with EmbeddedId -> "Unknown Column" Error
PostPosted: Wed Sep 22, 2010 7:47 am 
Newbie

Joined: Tue Sep 21, 2010 12:43 pm
Posts: 6
Here is my code of the Embeddable class:

Code:
@Embeddable
public class PropertyValuePK implements Serializable {
    private Long articleId;

    @Basic
    @Column(name = "artikelId")
    public Long getArticleId() {
        return articleId;
    }

    public void setArticleId(Long articleId) {
        this.articleId = articleId;
    }

    private PropertyNameEntity propertyNameEntity;

    @ManyToOne
    @JoinColumn(name = "eigenschaftsNameId")
    public PropertyNameEntity getPropertyNameEntity() {
        return propertyNameEntity;
    }

    public void setPropertyNameEntity(PropertyNameEntity propertyNameEntity) {
        this.propertyNameEntity = propertyNameEntity;
    }

... equals ...

... hashCode ...



Top
 Profile  
 
 Post subject: Re: Criteria Query with EmbeddedId -> "Unknown Column" Error
PostPosted: Wed Jan 02, 2013 12:57 pm 
Newbie

Joined: Fri Nov 23, 2012 2:04 pm
Posts: 2
Hi, I have same problem in my application, you find any solution?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.