-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem to achieve the where clause in self join
PostPosted: Wed Jun 27, 2007 1:36 pm 
Newbie

Joined: Fri Mar 02, 2007 5:59 am
Posts: 2
Table name : Tblsitemaplinks (hbm file )

<set
inverse="true"
lazy="true"
name="tblrolelinks"
>
<key column="LinkID" />
<one-to-many class="Tblrolelinks" />
</set>


Table Name : Tblrolelinks ( hbm file )

<many-to-one
name="linkID"
column="LinkID"
class="Tblsitemaplinks"
not-null="true"
>
</many-to-one>
<many-to-one
name="roleID"
column="RoleID"
class="Tblroles"
not-null="true"
>
</many-to-one>

CLASS:
public Tblrolelinks (
java.lang.Integer id,
com.comapnyABC.comapnyNAME.core.common.Tblsitemaplinks linkID,
com.comapnyABC.comapnyNAME.core.common.Tblroles roleID,

java.lang.Integer status,
java.lang.Integer displayorder,
java.lang.String addedBy,
java.util.Date dateAdded,
java.lang.String updatedBy,
java.util.Date dateUpdated) {

SQL Query : Select LinkContent, LinkID, LinkParent, Level from tblsitemaplinks where LinkID in (select distinct LinkID from tblrolelinks where RoleID=?) and Status=1 order by Displayorder

SQL Query with Inner Join:

select tbstmplnks.linkContent, tbstmplnks.id, tbstmplnks.linkParent,tbstmplnks.displayOrder, tbstmplnks.level from Tblsitemaplinks as tbstmplnks join tbstmplnks.tblrolelinks as tblrllnks where tblrllnks.roleID=1 and tblrllnks.status=1 order by tblrllnks.displayorder




Using Hibernate API:
List lst1 = (List) session.createCriteria(Tblsitemaplinks.class,"tblstmlnks").
add(Expression.eq("status",1)).createCriteria("tblrolelinks","tbrlnks").add(Restrictions.eq("tbrlnks.roleID",1)).list();



Genrated Query:
select this_.LinkID as LinkID33_1_, this_.LinkName as LinkName33_1_, this_.LinkContent as LinkCont3_33_1_, this_.LinkParent as LinkParent33_1_, this_.Level as Level33_1_, this_.DisplayOrder as DisplayO6_33_1_, this_.Status as Status33_1_, this_.AddedBy as AddedBy33_1_, this_.DateAdded as DateAdded33_1_, this_.UpdatedBy as UpdatedBy33_1_, this_.DateUpdated as DateUpd11_33_1_, tbrlnks1_.RoleLinkID as RoleLinkID6_0_, tbrlnks1_.Status as Status6_0_, tbrlnks1_.Displayorder as Displayo3_6_0_, tbrlnks1_.AddedBy as AddedBy6_0_, tbrlnks1_.DateAdded as DateAdded6_0_, tbrlnks1_.UpdatedBy as UpdatedBy6_0_, tbrlnks1_.DateUpdated as DateUpda7_6_0_, tbrlnks1_.LinkID as LinkID6_0_, tbrlnks1_.RoleID as RoleID6_0_ from tblsitemaplinks this_ inner join tblrolelinks tbrlnks1_ on this_.LinkID=tbrlnks1_.LinkID where this_.Status=? and tbrlnks1_.RoleID=?


My Question: I can achieve the same using the direct HQL, but I want to achieve using the hibernate API..I am getting error when I add this line add(Restrictions.eq("tbrlnks.roleID",1)) with the partial constructed call as shown above in Using Hibernate API. The attribute roleID is foreign key of table Tblroles. I am using hibernate-3.2.3 with mysql 5.2.
Error:

org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.comapnyABC.comapnyNAME.core.common.base.BaseTblroles.id at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171) at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183) at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3589) at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3305) at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:218)



Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


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

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.