Hibernate version: Hibernate 3.2.2
Name and version of the database you are using: Mysql 5
Hallo,
ich hab ein kleines Probelm. Und zwar versuche ich ein Objekt mit Hibernate abzuspeichern. Die Datenbank ist leer, dass Objekt wird also zum ersten mal abgelegt. Ich bekomme beim commit eine HibernateException (Stacktrace am Ende des Posts).
Wie gesagt, das Objekt wird zum ersten mal gespeichert und hat selbst noch keine ID.
Was mache ich falsche?!
Danke für die Antworten!
Hier der Code:
Code:
Session hibSession = null;
Transaction tx = null;
try{
hibSession = this.factory.openSession();
tx = hibSession.beginTransaction();
hibSession.save(session);
tx.commit(); // Hier kommt die Exception
} catch (HibernateException e) {
// ...
}
finally {
//...
}
hibernate.cfg.xml:
Code:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">java:comp/env/documentDataSource</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">false</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping resource="de/nepatec/edocbox/comserver/core/dto/TransferSessionDTO.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Mappingdatei:
Code:
<hibernate-mapping>
<class name="de.nepatec.edocbox.comserver.core.dto.TransferSessionDTO" table="TransferSession">
<id name="id" column="ID" type="integer">
<generator class="native"/>
</id>
<property
name="open"
column="OPEN"
type="boolean" />
<property
name="closed"
column="CLOSED"
type="boolean"
/>
<property
name="openDate"
column="openDate"
type="timestamp"
/>
</class>
</hibernate-mapping>
Code:
org.hibernate.HibernateException: identifier of an instance of de.nepatec.edocbox.comserver.core.dto.TransferSessionDTO was altered from 1 to 1
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:58)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:157)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at de.nepatec.edocbox.comserver.core.dao.hibernate.HibernateTransferSessionDAO.saveTransferSession(HibernateTransferSessionDAO.java:33)
at de.nepatec.edocbox.comserver.comchannel.serviceimpl.DocumentTransferServiceSkeleton.openTransferSession(DocumentTransferServiceSkeleton.java:130)
at de.nepatec.edocbox.comserver.comchannel.serviceimpl.DocumentTransferServiceMessageReceiverInOut.invokeBusinessLogic(DocumentTransferServiceMessageReceiverInOut.java:74)
at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.receive(AbstractInOutSyncMessageReceiver.java:39)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:497)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:328)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:254)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:615)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSubjectValve.java:56)
at org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:342)
at org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:31)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)