-->
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.  [ 1 post ] 
Author Message
 Post subject: org.hibernate.exception.ConstraintViolationException
PostPosted: Sun Mar 05, 2006 12:13 pm 
Newbie

Joined: Wed Aug 18, 2004 6:30 am
Posts: 14
Hello Hibernate Community !

Hopefully you can help me with a problem. I am writing an electronic flightlog and i have a problem with a many-to-one relation.
It seems that i get the same identifier twice from the hilo table. but i don't know why :(
I get the exception mentioned below.

Thanks for your help in advance!!

Hibernate version:
3.0

Mapping documents:
<hibernate-mapping>
<class name="com.martkoch.flightlog.model.Pilot" table="person" catalog="flightlog">
<id name="idPerson" type="integer">
<column name="id_person" />
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">hibernate_key</param>
<param name="column">next_hi</param>
</generator>
</id>
<property name="firstname" type="string">
<column name="firstname" length="45" not-null="true" />
</property>
<property name="lastname" type="string">
<column name="lastname" length="45" not-null="true" />
</property>
<property name="licenseNumber" type="integer">
<column name="license_number" not-null="true" />
</property>
<property name="licenseValidity" type="timestamp">
<column name="license_validity" length="19" not-null="true" />
</property>

<one-to-one name="flightlog"/>

</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="com.martkoch.flightlog.model.Flightlog" table="flightlog" catalog="flightlog">
<id name="idFlightlog" column="id_person" >
<generator class="foreign">
<param name="property">pilot</param>
</generator>
</id>

<one-to-one name="pilot"
constrained="true" />

<property name="startDate" type="timestamp">
<column name="start_date" length="19" not-null="true" />
</property>
<property name="name" type="string">
<column name="name" length="45" not-null="true" />
</property>

<set name="flights" cascade="all">
<key column="id_flight"/>
<one-to-many class="com.martkoch.flightlog.model.Flight"/>
</set>

</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="com.martkoch.flightlog.model.Flight" table="flight" catalog="flightlog">
<id name="idFlight" type="integer">
<column name="id_flight" unique="true"/>
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">hibernate_key</param>
<param name="column">next_hi</param>
</generator>
</id>
<property name="starttime" type="timestamp">
<column name="starttime" length="19" not-null="true" />
</property>
<property name="stoptime" type="timestamp">
<column name="stoptime" length="19" not-null="true" />
</property>
<property name="comment" type="string">
<column name="comment" length="65535" not-null="true" />
</property>

<many-to-one name="flightlog"
column="id_flightlog"
class="com.martkoch.flightlog.model.Flightlog"/>

<property name="nubmerLandings" type="integer">
<column name="number_landings" not-null="true" />
</property>

</class>
</hibernate-mapping>




Code between sessionFactory.openSession() and session.close():
Transaction myTrans = mySession.beginTransaction();

Pilot pilot = new Pilot();
pilot.setFirstname("Martin");
pilot.setLastname("Koch");
pilot.setLicenseNumber(new Integer(12280));
pilot.setLicenseValidity(new Date());

Flightlog myLog = new Flightlog();
myLog.setPilot(pilot);
myLog.setName("Martins FlightLog");
myLog.setStartDate(new Date());

Flight firstFlight = new Flight();
firstFlight.setFlightlog(myLog);
firstFlight.setStarttime(new Date());
firstFlight.setStoptime(new Date());
firstFlight.setComment("First flight");
firstFlight.setNubmerLandings(new Integer(3));

Flight secondFlight = new Flight();
secondFlight.setFlightlog(myLog);
secondFlight.setStarttime(new Date());
secondFlight.setStoptime(new Date());
secondFlight.setComment("Second flight");
secondFlight.setNubmerLandings(new Integer(4));

Set flights = new HashSet();
flights.add(firstFlight);
flights.add(secondFlight);

myLog.setFlights(flights);

mySession.save(myLog);
mySession.flush();

myTrans.commit();


Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at com.martkoch.flightlog.test.MyTest.main(MyTest.java:65)
Caused by: java.sql.BatchUpdateException: Duplicate entry '1114112' for key 1
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1566)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)

Name and version of the database you are using:
MySQL 5.0


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.