Hi there,
I've been searching the Internet for a solution the entire friday...i've been searching this forum and found some topics about this, but not exactly what i need and what kind of problem i have.
I have a Person (a doctor) that has to execute controls whether or not employees are accually legally absent.
The doctor has to perform controls in several regions. A doctor has base regions, and extended regions.
I have a class Party with two subclasses Person and Organisation. A Person has 2 links with DoctorRegion (an intermediate table between a Person and a Region ... separate class is needed due to more columns (like audit information) in the intermediate table.
A Region class consists of a mapping to both the Region table and the RegionCode table.
More will be clear when you see my mappings.
Party/Person-mapping
Code:
<class name="Party" table="PARTY_VIEW">
<id name="id" column="PAR_ID" type="long">
<generator class="native">
<param name="sequence">SEQ_PAR</param>
</generator>
</id>
...
<joined-subclass name="Person" table="PERSON_VIEW">
<key column="PER_ID" not-null="true"/>
<set name="baseRegions" where="TYPE='B'" lazy="true"
cascade="all,delete-orphan" inverse="true" >
<key column="PAR_ID" not-null="true"/>
<one-to-many class="DoctorRegion"/>
</set>
<set name="extendedRegions" where="TYPE='E'" lazy="true"
cascade="all,delete-orphan" inverse="true">
<key column="PAR_ID" not-null="true"/>
<one-to-many class="DoctorRegion"/>
</set>
...
DoctorRegion-mappingCode:
<hibernate-mapping package="be.fgov.health.absent.model">
<class name="DoctorRegion" table="DOCTOR_REGIONS">
<composite-id name="id" class="DoctorRegionId">
<key-many-to-one name="person" class="Person" column="PAR_ID"/>
<key-many-to-one name="region" class="Region" column="RGN_ID"/>
</composite-id>
<property name="type" column="TYPE" type="string" length="1"
not-null="true"/>
<property name="createdBy" column="CREATED_BY" type="string"
length="50" not-null="true"/>
<property name="updatedBy" column="UPDATED_BY" type="string"
length="50"/>
</class>
</hibernate-mapping>
Region-mappingCode:
<hibernate-mapping package="be.fgov.health.absent.model">
<class name="Region" table="REGION">
<id name="id" column="RGN_ID" type="long">
<generator class="native">
<param name="sequence">SEQ_RGN</param>
</generator>
</id>
<property name="description" column="DESCRIPTION" type="string"
length="255" not-null="true"/>
<property name="active" column="ACTIVE" type="yes_no"
not-null="true"/>
<property name="createdBy" column="CREATED_BY" type="string"
length="50" not-null="true"/>
<property name="updatedBy" column="UPDATED_BY" type="string"
length="50"/>
<join table="REGION_CODES">
<key column="RGN_ID"/>
<property name="postalCode" column="POSTAL_CODE" type="long"
unique="true" not-null="true"/>
<property name="regionCodeCreatedBy" column="CREATED_BY"
type="string" length="50" not-null="true"/>
<property name="regionCodeUpdatedBy" column="UPDATED_BY"
type="string" length="50"/>
</join>
</class>
</hibernate-mapping>
This is my test where all goes wrong:Code:
session = this.getSession();
Person loadedPerson = (Person)session.load(Person.class,
person.getId());
assertNotNull(loadedPerson);
assertNotNull(loadedPerson.getBaseRegions());
// temporaryTest(loadedPerson);
assertEquals(1, loadedPerson.getBaseRegions().size());
I can already save separate Regions (not linked to a person, so no DoctorRegions), it works, it has been tested in a JUnit.
Now i want links between a Person and a Region. I have two sets, one set for base regions ( type = B ) and one set for extended regions ( type = E ).
According to the hibernate reference it should be possible to give a where condition in a <set> mapping to only load those objects who fullfill the condition in that set. But it doesn't work. I added one base region to the baseRegions set, and one extended region to the extendedRegions set...
but when i load loadedPerson.getBaseRegions, its size is 2, not 1 ... and both the base and the extended region are in that same set of base regions.
I already tried ( i read somewhere on the internet this is a bug in AbstractCollectionPersister ) to call something else, like iterator() on the set, iterate over it and print the contents, but it is the same error...
I also tried to fill the table="" attribute in the set to refer to DOCTOR_REGIONS, i tried editing the where to where="DoctorRegions.type = 'E'" or where="DOCTOR_REGIONS.TYPE = 'E'" or where="DOCTOR_REGIONS.TYPE LIKE 'E'", but non worked...
I have a .patch file somewhere ( AbstractCollectionPersister.patch ) but i have no clue on how to install and build it again ... and it has to be used by all developers, and it has to run on Oracle Portal.
Can anyone give me any hint on why this "where-clause" in the set doesn't work, and what can be done about it? Or how i can install the patch?
I already have a temporary solution ... just making one set with all regions in it, and making 2 methods in my person class that iterate the one set ... and create another set where only the wanted regions are added in, and return thatone. So instead of letting hibernate do the work for me, i have to do the work myself.
Can anyone help? Thank you very much.
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1
Mapping documents: See above
Code between sessionFactory.openSession() and session.close(): Not applicable
Full stack trace of any exception that occurs: AssertionFailedExceptionError: expected:<1> but was:<2>
Name and version of the database you are using: Oracle 10g (10.1)
The generated SQL (show_sql=true): See above
Debug level Hibernate log excerpt: Not applicable