-->
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.  [ 3 posts ] 
Author Message
 Post subject: Discriminator not working right
PostPosted: Thu May 31, 2007 7:37 pm 
Newbie

Joined: Thu May 31, 2007 7:24 pm
Posts: 4
In my current database we use logical deletions. This means that there could be many items with the same id, but we enforce that only one of them is active (i.e. the column is_active=Y) at any given time. However, the basic Session.get() doesn't look at any columns other than the given id column, so if I try to call get on an identifier that has several instances, it will fail since multiple rows will be found, even though only one of those rows has is_active=Y.

I am trying to use discriminators to get around this, but for some reason the query that is being generated is the same both with and without the discriminator. Here is the mapping file:
=====================================
<hibernate-mapping>
<class name="MyHost" table="HOSTS" discriminator-value="Y">
<id name="hostName" column="HOST_NAME">
<generator class="native"/>
</id>
<discriminator column="IS_ACTIVE" type="character"/>
</class>
</hibernate-mapping>
====================================
And here's how I call the get:
====================================
SessionFactory factory = new Configuration().configure().buildSessionFactory();

Session session = factory.getCurrentSession();

session.beginTransaction();

MyHost host = (MyHost)(session.get(MyHost.class, "my.test.host.com"));
=====================================
However, the query that Hibernate generates is:
=====================================
select myhost0_.HOST_NAME as HOST1_0_0_ from HOSTS myhost0_ where myhost0_.HOST_NAME=?
=====================================
As you can see, no mention of myhost0_.IS_ACTIVE. What am I doing wrong? Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 3:17 am 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
Try this:
<hibernate-mapping>
<class name="MyHost" table="HOSTS" where="IS_ACTIVE='Y'">
...
..

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 11:10 am 
Newbie

Joined: Thu May 31, 2007 7:24 pm
Posts: 4
Yep, that got it. Thanks :)


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