-->
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: discriminator. I want to ignore some values?
PostPosted: Mon Jan 07, 2008 9:39 am 
Newbie

Joined: Fri Jan 05, 2007 5:36 am
Posts: 16
I'm mapping from an old database right now.
There is some values that need to be there and can't be changed but I don't want them when I retrieve my objects.
Right now I have a discriminator that maps the objects right but here comes the problem.
I don't know how to leave some of the values out from the discriminator?

Let's say the column contains values from 1-17. I only want it to return values from 1-10 and 16-17.

I have tried some different solutions but none of them have worked so far.
How can this be done?


Cheers,

Yagami.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 2:53 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
yagami,

Two possible solutions:
1) create a view on your database and map to that, as if it were a normal table.
2) Make a "subselect" class (Chapter 5.1.3)

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 4:19 am 
Newbie

Joined: Fri Jan 05, 2007 5:36 am
Posts: 16
Thanks a lot!

I created a view and now everything works like a charm.
My only question now is how NHibernate will handle insert and updates.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 10:35 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Yagami,
What worked for me, is to have 2 versions of the entity: one "full" and one "abridged". The "abridged" is the one that has the view or subselect ad backend, and the "full" is the one that you would use when you need to update/insert/delete.

Notice that Hibernate does not like many objects floating around with the same ID, so, in order for this solution to work, you would have to make the "full" id a property of the "abridged" id, and indicate in the mapping file that "abridged" takes its ID from "full". This is indicated with the id generator called "foreign", in the following way:

Code:
<class name="abridgedClass">
  <id name="id" column="classId">
    <generator class="foreign">
      <param name="property">fullClass</param>
    </generator>
  </id>
  ...
  <one-to-one name="fullClass" class="FullClass" constrained="true"/>
  ...
</class>

<class name="fullClass" table="fullClass">
...


(reference documentation 5.1.1)

_________________
Gonzalo Díaz


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.