-->
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.  [ 6 posts ] 
Author Message
 Post subject: 'where' property ignored on session.refresh()
PostPosted: Fri Aug 19, 2005 12:17 am 
Beginner
Beginner

Joined: Wed Jul 13, 2005 2:18 pm
Posts: 44
Been pulling my hair out all day trying to figure out a way to map some hibernate objects on top of a small portion of our ERP system, and I'm at a nasty impasse.

I've got the following mapping file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="domain">
<class mutable="false" name="domain.Student" table="spriden" where="spriden_change_ind is null">
  <id column="spriden_pidm" name="pidm">
   <generator class="native"/>
  </id>
  <property column="spriden_first_name" name="firstName"/>
  <property column="spriden_last_name" name="lastName"/>
  <property column="spriden_id" name="bannerId"/>
  <property column="spriden_mi" name="middleName"/>
  <one-to-one cascade="save-update"
   class="domain.StudentInfo" name="studentInfo" outer-join="false"/>
</class>
</hibernate-mapping>


Nice and straightforward. Notice the where attribute - it's there because spriden_pidm isn't *actually* unique...there are duplicates. I know, I know, I need to map a primary key, right? Well, that's the best I can do. spriden_pidm is *supposed* to be a unique number, but because the ERP system (which may look familiar some of you who've worked at a medium/large university) is designed to be ultra-general purpose, it lacks integrity constraints. Even worse, having duplicate pidms happens all the time as a normal part of the process of cleaning up duplicate accounts (which happens more often than I care to think about). There's a way to filter out the bad dups of course - on the good record, the spriden_change_ind field is null, hence the where clause.

Except that when I do a session.refresh() on an object from this table, the hibernate generated sql leaves off the where clause:
Code:
select student0_.spriden_pidm as spriden_1_0_,
student0_.spriden_first_name as spriden_2_0_,
student0_.spriden_last_name as spriden_3_0_,
student0_.spriden_id as spriden_id0_,
student0_.spriden_mi as spriden_mi0_
from spriden student0_
where student0_.spriden_pidm=?

I suppose that's perfectly reasonable if the underlying database plays by the rules, but given the options hibernate provides for dealing with databases that *don't* play by the rules, it feels like there should be a way to change this behavior.

Is there perhaps some special option I can tweak somewhere? If not, could one of the developers or gurus point me in the direction of the code I'd need to change in the library to enable the behavior I need?

I won't go into it since it's unrelated, but there's an awfully gross reason I happen to be calling session.refresh() on those objects which involves loading them by native sql query from an entirely different pseudo-replicated datasource =) Ah, the joys of enterprise software and integration...

_________________
- Matt


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 12:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Specify a native SQL <loader>.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 12:28 am 
Beginner
Beginner

Joined: Wed Jul 13, 2005 2:18 pm
Posts: 44
Thanks for the quick response! It's certainly not my intenion to be lazy, but I can't find a reference to a loader anywhere in the manual, or in the places I could think of looking in the javadoc. I presume by your use of <> that loader is a tag I can stick in the mapping file?

I forgot to indicate in my first post that I'm using 2.1 as well - are these <loader>s supported in the older version?

_________________
- Matt


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 12:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, this is HB3


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 12:32 am 
Beginner
Beginner

Joined: Wed Jul 13, 2005 2:18 pm
Posts: 44
I was afraid of that. I'll check into it as soon as I get a chance, but off the top of your head how much trouble do you think it would cost me to hack the code to include that where clause when generating the query on a refresh?

_________________
- Matt


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:31 am 
Beginner
Beginner

Joined: Wed Jul 13, 2005 2:18 pm
Posts: 44
Aha - found the pertinent info in the manual. Guess I wasn't thinking terribly straight last night =) Thanks so much for the ridiculously prompt answer, I'll get started on migrating our code to Hibernate 3.0. There happens to be another feature added in 3 that my manager has been asking for specifically for a while now ;)

Thanks Gavin!

_________________
- Matt


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