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: [1.0.4] - override static where condition
PostPosted: Thu Aug 23, 2007 12:50 pm 
Beginner
Beginner

Joined: Tue Mar 14, 2006 9:15 am
Posts: 20
Location: Bitonto (BA) Italy
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
1.0.4

Mapping documents:

<class
name="ObjectModel.Config.AppConfig, ObjectModel"
table="Config_AppConfig"
where="arbitrary sql where condition">
<id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
<generator class="hilo">
<param name="table">NH_Key_Config</param>
<param name="column">Config_AppConfig</param>
<param name="max_lo">0</param>
</generator>
</id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<property name="Description" column="Description" type="String" />
</class>

-------------------------------

I have defined a where condition (as you can see above).

How can I override at runtime the where condition?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 24, 2007 12:08 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
I don't think you can, but keep in mind that defining that where condition there implies that said condition is integral to the composition of your class. That "overriding" it makes sense at all implies otherwise, so perhaps you should consider a different mechanism?

IOW, what are you trying to accomplish?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 24, 2007 3:03 am 
Beginner
Beginner

Joined: Tue Mar 14, 2006 9:15 am
Posts: 20
Location: Bitonto (BA) Italy
marcal wrote:
IOW, what are you trying to accomplish?


Suppose to have a class with flag IsAlive. The 99% usage is to load items with IsAlive = true, but for a specific use case (a report) I want to show all the records (dead or alive).

Now the application contains already many calls to GetItems<MyClass> so the solution has to be as trasparent as possible.

TIA.

tommaso


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 24, 2007 1:12 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
I don't know of a direct override, but off the top of my head here are two possible indirect solutions:

Reporting class: Create a new, lightweight class and read-only (mutable=false) mapping for reporting on data from the same table. Query for that class when reporting.

Reporting factory: Create a new read-only (again, mutable=false) mapping to the same class, but don't include it in your main-use configuration/session factory. If you are using Configuration.AddAssembly(), you might keep it out by naming it with a '.rhbm.xml' extension. Then build another configuration, but add only this (and other reporting) mapping(s), perhaps using AddResource(). From this you can build a "reporting ISessionFactory" and when you need to load your objects for reporting purposes you can open a session from there.

The latter may have the advantage that if you want to work with a "living" object taken from the report interface, you should be able to use it in your main-use factory (after closing the reporting ISession or evicting the object therefrom).

Note that this is just brainstorming, I haven't tested or actually used either option.


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.