-->
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.  [ 2 posts ] 
Author Message
 Post subject: Create Listener. No DefaultCreateEventListener to extend
PostPosted: Wed Mar 16, 2005 12:10 pm 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
Hibernate version:
3.0 rc1
Mapping documents:
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" />
   
   <property name="documentSubTypeID" column="documentSubTypeID" type="java.lang.Long" not-null="true"/>
   
    <many-to-one name="policyNumber" column="policyNumberId" class="PolicyNumber" cascade="save-update"/>
  </class>
</hibernate-mapping>


Code:
<hibernate-mapping package="com.llic.business">
 
  <joined-subclass name="Application" extends="Document" table="Application" >
   
    <key column="DocumentID"/>
   
    <!-- needs to be a db generated id or null.  setApplicationId() should not be publicly visible -->
    <property name="applicationId" column="applicationId" type="java.lang.Long" unique="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">
      <!-- foreign key in appentityrole is application id which references the local property applicationId -->
      <key column="applicationId" property-ref="applicationId" />
      <one-to-many class="com.llic.business.ApplicationEntityRole" />
    </set>

  </joined-subclass>
 
</hibernate-mapping>


I need to generate id’s natively on joined-subclasses for a legacy database.
I have come up with two possible solutions to handle this situation; the first seems to be the best. Any recommendations would be appreciated.

Solution 1:

Utilize the new event system in Hibernate 3. I would like to create a listener on create, that will check for properties such as applicationId. These properties are generated as an Identity by DB2, and thus on the create event I need to utilize the native generator semantics.

I have three questions.

1. Is there some example of a Create event I can look at?
2. Is there some way I can specify that this property needs to be created by the event in the mapping? This will allow me to keep my non-id (to the java side) generated properties mapped with the class in a central location.
3. Is simply retrieving the dialect and calling getIdentityInsertString() enough to get the default insert string? Once I have done this, what is the best way to get the new identities without extending BasicEntityPersister's insert method?

Solution 2:

Extend BasicEntityPersister and JoinedSubclassEntityPersister.
Override insert to retrieve the identity columns (I'll have two on an insert, the mapped Document.id, and Application.applicationId).
This seems like a huge headache, but if someone thinks it would be more efficient, please let me know.

Todd

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 12:42 pm 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
I have figured out the create event persister, I am just extending DefaultPersistEventListener


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