Beginner |
|
Joined: Tue May 23, 2006 4:10 pm Posts: 38 Location: Charleston, SC
|
I'm using the latest version of Hibernate and have a couple of questions about ID generation when persisting XML entities. I saw nothing in the docs that said ID generation was not supported for XML persistence? During my testing, Hibernate throws the exception (shown below) if I try to save the XML with ID generation:
<hibernate-mapping>
<class
entity-name="Arrival"
table="Arrival"
schema="dbo"
catalog="SeaHawk_Repository"
node="Arrival">
<id column="arrivalId" node="@sourceIDText">
<generator class="guid"/>
</id>
<property node="ArrivalDate" type="timestamp">
<column name="arrivalDate"/>
</property>
<property node="DepartureDate" type="timestamp">
<column name="departureDate"/>
</property>
<component node="ToLocation">
<property name="LocationName" node="LocationName" type="string" column="toLocation"/>
</component>
<component node="FromLocation">
<property name="LocationName" node="LocationName" type="string" column="fromLocation"/>
</component>
</class>
</hibernate-mapping>
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): Arrival
at org.hibernate.id.Assigned.generate(Assigned.java:33)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:642)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:616)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:620)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy52.persist(Unknown Source)
at gov.seahawk.portal.DataFeed.saveArrivals(DataFeed.jpd:158)
at gov.seahawk.portal.DataFeed_wf$ImplPerform7.invoke(DataFeed_wf.java:66)
at com.bea.wli.bpm.runtime.Perform.execute(Perform.java:32)
at com.bea.wli.bpm.runtime.Receive.messageDelivery(Receive.java:91)
at com.bea.wli.bpm.runtime.Receive.messageDeliveryAction(Receive.java:71)
at com.bea.wli.bpm.runtime.ProcessState.processMessage(ProcessState.java:166)
at gov.seahawk.portal.DataFeed_wf$_ProcessState.processMessage(DataFeed_wf.java:206)
at gov.seahawk.portal.DataFeed_wf.subscribeToSPA(DataFeed_wf.java:175)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:371)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:423)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:396)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:248)
at com.bea.wlw.runtime.core.bean.BaseContainerBean.invokeBase(BaseContainerBean.java:224)
at com.bea.wlw.runtime.core.bean.SLSBContainerBean.invoke(SLSBContainerBean.java:103)
at com.bea.wlwgen.DataFeedSLSBContImpl.subscribeToSPA(DataFeedSLSBContImpl.java:25)
at com.bea.wlwgen.StatelessContainer_342xuv_ELOImpl.subscribeToSPA(StatelessContainer_342xuv_ELOImpl.java:99)
at com.bea.wlwgen.DataFeedSLSBContAdpt.invokeOnBean(DataFeedSLSBContAdpt.java:54)
at com.bea.wlw.runtime.core.bean.BaseDispatcherBean.runAsInvoke(BaseDispatcherBean.java:153)
at com.bea.wlw.runtime.core.bean.BaseDispatcherBean.invoke(BaseDispatcherBean.java:54)
at com.bea.wlw.runtime.core.bean.AsyncDispatcherBean.onMessage(AsyncDispatcherBean.java:248)
at weblogic.ejb20.internal.MDListener.execute(MDListener.java:370)
at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:262)
at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:2678)
at weblogic.jms.client.JMSSession.execute(JMSSession.java:2598)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
If I remove the ID generation from the mapping file, set the ID attribute on the XML element before calling save on the session, the XML is inserted. My first question: Does Hibernate 3 support ID generation when mapping XML entities? If not, is there a way I can use the ID generation framework of Hibernate outside the mapping file to generate IDs for my XML entities?
Grant
|
|