-->
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.  [ 5 posts ] 
Author Message
 Post subject: Modify where clause in mapping programatically?
PostPosted: Thu Feb 12, 2004 12:52 pm 
Newbie

Joined: Wed Jan 21, 2004 6:01 pm
Posts: 1
I am using the 'where' attribute in the <set> element quite successfully. However, for reasons of maintainability I would like to be able to externalise the content of the where clause so that I don't end up with a mapping file that, potentially, contains a large ugly 'where' attribute. I could then, at runtime, lookup the mapping and modify the 'where' clause programatically.
I looked at the Hibernate JavaDoc and it seems like I should be able to get to the mapping structure and, at the very least, display the where clause. When I attempt to do so however, using the following code, I just get a null value.
That problem aside, even if I could get at the where clause, it doesn't appear to be possible to modify it, i.e. there is no setter. Suggestions?

I realise that an alternative approach would be to use the query API to explicitly perform a query but I would very much like to fully leverage the lazy loading capabilities and stay away from unnecessary use of the query API when I don't strictly need to use it. As I said, the mapping file works perfectly as it is.

Thanks,

Scott.

Sample code:
PersistentClass pc = _config.getClassMapping(Order.class);
log.debug(pc.getName() + ", where = " + pc.getWhere());
PersistentClass pc = _config.getClassMapping(Item.class);
log.debug(pc.getName() + ", where = " + pc.getWhere());

Output:
ListMappings - Order, where = null
ListMappings - Item, where = null

Mapping:
<hibernate-mapping>
<class
name="Order"
table="ORDER"
proxy="Order">
<id name="id" column="ID">
<generator class="assigned"/>
</id>
<set name="licenseItems"
lazy="true"
where="PART_NUMBER IN ('555-6666', '111-2222')">
<key column="HEADER_ID"/>
<one-to-many class="Item"/>
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 12:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is Collection.getWhere().


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 12:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I don't really know if this is an error or just wrong usage, but you are digging around really deep inside the Configuration Object. Probably it would be easier if you just parse the Mapping File yourself, manipulate the where attribute in the DOM tree and then pass the tree to configure().


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 4:34 pm 
Beginner
Beginner

Joined: Wed Sep 17, 2003 4:07 pm
Posts: 22
I'm also looking at a way to change the Where clause of a lazy collection at runtime.

Is it advisable to change the Where cluase using Collection.setWhere()? If so, will it permanently change the Where clause for the lazy collection till the SessionFactory is alive or only for that transaction?

Thanks


Top
 Profile  
 
 Post subject: java.lang.ClassCastException in blob persistence
PostPosted: Thu May 27, 2004 4:09 pm 
Newbie

Joined: Thu May 27, 2004 10:42 am
Posts: 2
Hi Shansud,

I saw your posting java.lang.ClassCastException in blob persistence posted on Wed Sep 17, 2003 8:08 pm .

I am sorry for discussing about this topic here. I wanted to know if you got that problem fixed? If so, how did you solve it?

I also have the same problem. I have also used the same code (UserType).

I appreciate your response

Thanks


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