Hibernate version:
3.0rc1
We are beginning development with Hibernate 3, and I will wait for Spring to release 1.2 with Hibernate 3 support. I have the following object scenario
-> = Excends
#> = Foregin Key to primary key.
Object setup
Application -> Document
Application has many ApplicationEntityRoles
Database setup
Application #> Document (joined sublcass by document id, that part is easy)
ApplicationEntityRole #> Application.
NOTE: Application has is own primary key, and this is required by legacy apps!
Anthony mentioned in his earlier posts that a column and a formula could be used. I've reviewed the documentation, and it is not clear to me how to utilize this. Is there an example somewhere? Also, from my understanding of Hibernate, if I map a Set of AppliationEntityRoles into the Appliation mapping, it will be default use the primary key in Document correct?
Take the following example mappings...
Document
Code:
<hibernate-mapping package="com.llic.business">
<class name="Document" table="Document" polymorphism="implicit">
<id name="id" column="documentid">
<generator class="native" />
</id>
<property name="contentMgrUniqueKey" column="contentMgrUniqueKey" type="string" not-null="true" />
<property name="dateReceived" column="DATERECEIVED" type="java.util.Date" not-null="true" />
<property name="scanPacketNumber" column="packetnumber" type="string" />
</class>
</hibernate-mapping>
Application
Code:
<hibernate-mapping package="com.llic.business" >
<joined-subclass name="Application" extends="Document" table="Application" >
<key column="DocumentID"/>
<!-- the tables primary key, how would I map this -->
<property name="applicationId" column="applicationid" type="java.lang.Long" not-null="true"/>
<property name="policyDate" column="policydate" type="java.util.Date" not-null="false"/>
<property name="applicationDate" column="applicationDate" type="java.util.Date" not-null="false"/>
<set name="appEntityRoles" table="APPENTITYROLE" inverse="true" lazy="false" cascade="all">
<key column="applicationId"/>
<one-to-many class="com.llic.business.ApplicationEntityRole"/>
</set>
</joined-subclass>
</hibernate-mapping>
ApplicationEntityRole
Code:
<hibernate-mapping package="com.llic.business" >
<class name="ApplicationEntityRole" table="AppEntityRole" >
<id name="id" column="appEntityRoleId" type="java.lang.Long">
<generator class="native"/>
</id>
<property name="entityRoleTypeType" column="entityRoleTypeTypeId" type="java.lang.Long" not-null="true"/>
</class>
</hibernate-mapping>
When the sql is generated, won't this join APPENTITYROLE.ApplicationID = Document.DocumentID? I will also have an issue on the insertion of Application. The only solution I can think of is to extend JoinedSubclassEntityPersister, but this just feels like a hack to me. That would take care of the issue of persisting a new Application, but it will not help with joining APPENTITYROLE.ApplicaitonID with DOCUMENT.documentID. Does anyone have any suggestions? I'm stumped and I really need a hand.
Thanks,
Todd