-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate XDoclet tag where attribute with dynamic value?
PostPosted: Mon Nov 03, 2008 4:12 am 
Newbie

Joined: Mon Nov 03, 2008 3:26 am
Posts: 1
How to set dynamic value for where condition in xdcolet tag?

Xdoclet tag used to load child collections
/**
* @hibernate.set role="orders" lazy="true" order-by="name asc" where="online_language=? "
* @hibernate.collection-key column="id"
* @hibernate.collection-one-to-many class="classname"
*/
public Set getMembers() {

return (this.members);
}

Generated hbm
<set name=”members”
lazy=”true”
where= “online_language=? “>
<key column= “id”>
<one-to-many class=”classname”>
</set>

Java Code to Load child entity after loading parent object

createHBQuery("from parent as d "
+ "where d.Id = :id and d.onlineLang =:onlineLang order by d.sort");

getHBQuery().setParameter("Id", id);
getHBQuery().setParameter("onlineLang", onlineLangcode);

List phDataList = getHBQuery().list();
if (phDataList != null && phDataList.size() == 1){
Parent phData = (Parent) phDataList.get(0);
Hibernate.initialize(phData.getMembers());
return phData;
}


Generate sql query
select parent_.id as contract1_1_, parent_.mail_group as mail2_1 where parent _.contract_id=? and parent _.online_language=? order by parent_.sort
select members0_.contract_id as contract1_1_, members0_.partner_id as partner2_1_from members members0_ where ( members0_.online_language=? ) and members0_.contract_id=? order by members0_.name asc


Error Got

07:43:51,647 WARN [JDBCExceptionReporter] SQL Error: 17041, SQLState: null
07:43:51,647 ERROR [JDBCExceptionReporter] Missing IN or OUT parameter at index:: 2


Is there any way to set the where condition parameter value dynamically?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2008 4:50 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I don't think the where attribute can be used in this way. I believe it has to be a static condition.

The filter feature of Hibernate is more close to what you need. In your <set> mapping you can add a filter definition:

Code:
<filter name="langCode" condition=":onlineLang = online_language"/>


Then, filters are enabled/disabled on a Session level:

Code:
session.enableFilter("langCode").setParameter("onlineLang", onlineLangcode);


Read more about this on: http://www.hibernate.org/hib_docs/v3/re ... lters.html


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