Hibernate version: 3.1
Name and version of the database you are using: Oracle
Database information:
Table Person:
integer PERSON_ID primary key;
varchar FIRST_NAME;
integer CREATE_USER_ID foreign key references PERSON_ID;
Person table has a PERSON_ID which is a sequence and the primary key.
Person has a CREATE_USER_ID which is a foreign key reference to a PERSON_ID.
Test Person Data:
PERSON_ID = 84
FIRST_NAME = TestPerson
CREATE_USER_ID = 3
PERSON_ID = 3
FIRST_NAME = CreatePerson
CREATE_USER_ID = 3
Java information:
public class Person {
private UserTimestamp createUserTimestamp;
private long objectId;
private String firstName;
}
public class UserTimestamp {
private Person person;
private Date timestamp;
}
Problem:
I am trying to setup a hibernate mapping file where I can get hibernate to populate the UserTimestamp object with a Person from the database using the foreign key reference to an existing Person.
I can map fields on the Person just fine using components, I'm just having problems telling Hibernate to populate the Person object that is stored on a UserTimestamp using the primary/foreign key reference setup in the database. Here is some mapping code that does not seem to work:
Code:
<class name="Person" table="PERSON">
<id name="objectId" column="PERSON_ID">
<generator class="sequence">
<param name="sequence">PERSON_SEQ</param>
</generator>
</id>
<property name="firstName" column="FIRST_NAME" />
<component name="createUserTimestamp" class="UserTimestamp">
<many-to-one
cascade="none"
name="person"
class="Person"
column="PERSON_ID"
unique="true"
insert="false"
update="false"/>
<property name="timestamp" column="CREATE_DT"/>
</component>
</class>
Any help would be greatly appreciated, I realize that this isn't something that comes up in everyday use. One alternative I have is that in my DAOs, I can manually do the populating of the create person object myself instead of defining it in the mapping. However, I am curious if Hibernate has the power to do something like this - or if anyone else has a better solution.