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...