-->
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.  [ 11 posts ] 
Author Message
 Post subject: EJB3 QL problem
PostPosted: Sun Aug 13, 2006 9:18 am 
Beginner
Beginner

Joined: Sun Aug 13, 2006 8:40 am
Posts: 28
Hi I am using EJB QL and have the embedden version of Hibernate which is released with jboss-4.0.4.GA and am experiencing a query problrm which I cannot find a solution for. This is probably not an error, but my lack of knowledge in EJB QL.

I am trying to do this:
I have an entity (UserDescription) which have an instance of another entity (Role) with the data field 'name'. I am trying to get all instances of a UserDescription having a role named 'administrator', but I get an exception telling me that it can not resolve the property 'name'...

I am sorry for using the forum for this, but I do not where to turn... Can anyone help me?

Exception that occurs:
Code:
javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.QueryException: could not resolve property: name of: a.package.UserDescription [from a.package.UserDescription as ud fetch all properties where ( (ud.licenseHolderID = 0) ) and (ud.role.name = 'administrator')]


Debug level Hibernate log excerpt:
Code:
2006-08-13 14:31:33,703 DEBUG [org.hibernate.hql.ast.AST -  84] --- HQL AST ---
\-[QUERY] 'query'
    +-[SELECT_FROM] 'SELECT_FROM'
    |  \-[FROM] 'from'
    |     \-[RANGE] 'RANGE'
    |        +-[DOT] '.'
    |        |  +-[DOT] '.'
    |        |  |  +-[DOT] '.'
    |        |  |  +-[IDENT] 'a'
    |        |  |  \-[IDENT] 'package'
    |        |  \-[IDENT] 'UserDescription'
    |        +-[ALIAS] 'ud'
    |        \-[FETCH] 'fetch'
    \-[WHERE] 'where'
       \-[AND] 'and'
          +-[EQ] '='
          |  +-[DOT] '.'
          |  |  +-[IDENT] 'udd'
          |  |  \-[IDENT] 'myLicenseHolderID'
          |  \-[NUM_INT] '0'
          \-[EQ] '='
             +-[DOT] '.'
             |  +-[DOT] '.'
             |  |  +-[IDENT] 'ud'
             |  |  \-[IDENT] 'role'
             |  \-[IDENT] 'name'
             \-[QUOTED_STRING] ''administrator''


Hibernate version:
The default released version in JBoss Application Server 4.0.4.GA

Name and version of the database you are using:
Hypersonic SQL which is embedden in the JBoss release.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 9:44 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Can you post the mapping (annotations and/or xml) for the UserDescription-Role association?

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 9:48 am 
Beginner
Beginner

Joined: Sun Aug 13, 2006 8:40 am
Posts: 28
there are no annotations for the association.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 8:32 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Then at least a code snippet that stablishes the relation between UserDescription and Role

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 5:30 pm 
Beginner
Beginner

Joined: Sun Aug 13, 2006 8:40 am
Posts: 28
I thought a simple variable in an entity was a one to one relation by default. In the UserDescription it is:
Code:
Role role = null;


... and with getters and setters accordingly. The access of the data in the bean is by variable and not by getters and setters


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 9:05 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
A property like that could be either one-to-one or many-to-one, so you should sign which one you desire:
Code:
Role role;

@javax.persistence.ManyToOne
public Role getRole() {
    return role;
}
public void setRole(Role role) {
    this.role = role;
}


And if you want the other side to reversely map the relation too...
Code:
@OneToMany(mappedBy = "role")
public Set<UserDescription> getUserDescriptions() {
    /* the usual accessor, field and modifier */
}

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 11:26 am 
Beginner
Beginner

Joined: Sun Aug 13, 2006 8:40 am
Posts: 28
hlfsousa wrote:
A property like that could be either one-to-one or many-to-one, so you should sign which one you desire:
Code:
Role role;

@javax.persistence.ManyToOne
public Role getRole() {
    return role;
}
public void setRole(Role role) {
    this.role = role;
}


And if you want the other side to reversely map the relation too...
Code:
@OneToMany(mappedBy = "role")
public Set<UserDescription> getUserDescriptions() {
    /* the usual accessor, field and modifier */
}


... but do you need to have the annotation? ...and what purpose has the mappedBy parameter to the annotation?

... and I am probably wrong when I say one to one as default. I ment one to many, which is to say that a user description can have a role and another description may have the same role...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 03, 2006 3:09 pm 
Beginner
Beginner

Joined: Sun Aug 13, 2006 8:40 am
Posts: 28
I had 3 weeks of vacation and hoped that this issue was solved when I returned, but it is not so simple...

Please help!

To summarize; I am trying to do this:
I have an entity (UserDescription) which have an instance of another entity (Role) with the data field 'name'. I am trying to get all instances of a UserDescription having a role named 'administrator', but I get an exception telling me that it can not resolve the property 'name'...

The instance of Role (Role is an entity bean) is a variable in the entity UserDescription and does not have any special annotation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 04, 2006 4:24 am 
Beginner
Beginner

Joined: Sun Aug 13, 2006 8:40 am
Posts: 28
...and here is my original query which is producing the exception:

Code:
from a.package.UserDescription as ud where  ( (ud.licenseHolderID = 0) ) and (ud.role.id in (select r.id from another.package.Role as r where r.name = 'administrator'))


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 04, 2006 7:01 am 
Beginner
Beginner

Joined: Sun Jan 22, 2006 6:56 am
Posts: 29
Why do you think that the property should be annotated? Hibernate needs to know the mapping between classes, either by *.hbm.xml mapping files or by annotations. Using annotations there simple properties are mapped by default (assuming you've annotated the class with @Entity), but associations require extra information.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 4:42 am 
Beginner
Beginner

Joined: Sun Aug 13, 2006 8:40 am
Posts: 28
I thought that properties of entity beans defaulted to the ManyToOne relation, but this is probably wrong as it is not working. However; Just stating @ManyToOne produce the same exception.

I also redesigned the query as it is not the role.id (every entity has a primary key (Long) which is generated) which is stated in the database but 'B@184b649' which seems to be a memory referance or something. Maybe this is because the relation is not stated...

The query (but it still produce the same type of exception stating that role is not mapped):
Code:
from a.package.UserDescription as ud where  ( (ud.licenseHolderID = 0) ) and (ud.role in (select r from another.package.Role as r where r.name = 'administrator'))


Please help me find a solution for this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.