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.  [ 5 posts ] 
Author Message
 Post subject: How to persist an author and his works
PostPosted: Sat Apr 02, 2005 7:03 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
Hibernate version:
3.0

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="hibernate.prov.model.Author" table="authors">

<id name="id" column="id">
<!-- The Author must have the same identifier as the Person -->
<generator class="assigned"/>
</id>

<property name="alias"/>
<one-to-one name="person" constrained="true"/>

<set name="works" table="author_work" inverse="false">
<key column="author_id"/>
<many-to-many class="hibernate.prov.model.Work" column="work_id"/>
</set>

</class>
</hibernate-mapping>



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="hibernate.prov.model.Person" table="persons">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="hibernate.prov.model.Work" table="works" discriminator-value="W">

<id name="id" column="id">
<generator class="native" />
</id>
<discriminator column="type" type="character" />

<property name="title" />
<set name="authors" table="author_work">
<key column="work_id" />
<many-to-many class="hibernate.prov.model.Author" column="author_id" />
</set>

<subclass name="hibernate.prov.model.Book" discriminator-value="B">
<property name="text" />
</subclass>

<subclass name="hibernate.prov.model.Song" discriminator-value="S">
<property name="tempo" />
<property name="genre" />
</subclass>

</class>
</hibernate-mapping>

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

Hi,

I am trying to implement the examples of the documentation.
I successed in implementing the Author/Work example.

My first question is, where could I download these examples.

My other question is about persisting an Author and his songs or books.
My working code to insert an author is :

Code:
public class InsertAuthors
{
   public static void main( String args[] )
   {
      Session session = HibernateUtil.currentSession();
      Transaction tx = session.beginTransaction();
      
      purgeAuthors( session );
      
      session.save( createJohn(session) );
      
      tx.commit();
      HibernateUtil.closeSession();
   }
   
   private static Author createJohn( Session session )
   {
      Long personId;
      Person person = new Person("john");
      
      personId = (Long)session.save( person );
      person.setId( personId );
      
      Author a = new Author();
      a.setPerson( person );
      a.setAlias( "jon" );
      
      HashSet works = new HashSet();
      
      Song w1 = new Song();
      w1.setTitle( "john's first song" );
      w1.setGenre( "reggae" );
      w1.setTempo( (float)1.22 );
      Integer id = (Integer)session.save( w1 );
      w1.setId( id );
      works.add( w1 );
      
      Song w2 = new Song();
      w2.setTitle( "john's second song" );
      w2.setGenre( "reggae" );
      w2.setTempo( (float)1.4 );
      id = (Integer)session.save( w2 );
      w2.setId( id );
      works.add( w2);
      
      Book w3 = new Book();
      w3.setTitle( "john's first book" );
      w3.setText( 10 );
      id = (Integer)session.save( w3 );
      w3.setId( id );
      works.add( w3 );
      
      a.setWorks( works );
      
      return a;
   }
}


The code I was hoping to use, but doesnt work :
Code:
public class InsertAuthors
{
   public static void main( String args[] )
   {
      Session session = HibernateUtil.currentSession();
      Transaction tx = session.beginTransaction();
      
      purgeAuthors( session );
      
      session.save( createJohn(session) );
      
      tx.commit();
      HibernateUtil.closeSession();
   }
   
   private static Author createJohn( Session session )
   {
      Long personId;
      Person person = new Person("john");
      
      personId = (Long)session.save( person );
      person.setId( personId );
      
      Author a = new Author();
      a.setPerson( person );
      a.setAlias( "jon" );
      
      HashSet works = new HashSet();
      
      Song w1 = new Song();
      w1.setTitle( "john's first song" );
      w1.setGenre( "reggae" );
      w1.setTempo( (float)1.22 );
      works.add( w1 );
      
      Song w2 = new Song();
      w2.setTitle( "john's second song" );
      w2.setGenre( "reggae" );
      w2.setTempo( (float)1.4 );
      works.add( w2);
      
      Book w3 = new Book();
      w3.setTitle( "john's first book" );
      w3.setText( 10 );
      works.add( w3 );
      
      a.setWorks( works );
      
      return a;
   }
}


The exception :
Exception in thread "main" org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: hibernate.prov.model.Song
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:210)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:88)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:42)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:656)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:878)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:23)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
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:675)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at hibernate.prov.InsertAuthors.main(InsertAuthors.java:30)


Is hibernate supposed to automatically persists the works when I persist an author ?

Thank you
Lilian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2005 9:44 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
Maybe was my previous question too much long, so I post it again in a shorter manner.

I am trying to implement the examples of the documentation.
I successed in implementing the Author/Work example.

My first question is, where could I download these examples.

My other question is about persisting an Author and his songs or books.
My working code to insert an author is :

Code:
public class InsertAuthors
{
   public static void main( String args[] )
   {
      Session session = HibernateUtil.currentSession();
      Transaction tx = session.beginTransaction();
     
      session.save( createJohn(session) );
     
      tx.commit();
      HibernateUtil.closeSession();
   }
   
   private static Author createJohn( Session session )
   {
      Long personId;
      Person person = new Person("john");
     
      personId = (Long)session.save( person );
      person.setId( personId );
     
      Author a = new Author();
      a.setPerson( person );
      a.setAlias( "jon" );
     
      HashSet works = new HashSet();
     
      Song w1 = new Song();
      w1.setTitle( "john's first song" );
      w1.setGenre( "reggae" );
      w1.setTempo( (float)1.22 );
      Integer id = (Integer)session.save( w1 );
      w1.setId( id );
      works.add( w1 );
     
      Song w2 = new Song();
      w2.setTitle( "john's second song" );
      w2.setGenre( "reggae" );
      w2.setTempo( (float)1.4 );
      id = (Integer)session.save( w2 );
      w2.setId( id );
      works.add( w2);
     
      Book w3 = new Book();
      w3.setTitle( "john's first book" );
      w3.setText( 10 );
      id = (Integer)session.save( w3 );
      w3.setId( id );
      works.add( w3 );
     
      a.setWorks( works );
     
      return a;
   }
}


I have tried to persist the author without persisting his works manually but I get "object references an unsaved transient instance - save the transient instance before flushing: hibernate.prov.model.Song"...

Is hibernat supposed to automatically persists the works when I persist an author ?

Best regards
Lilian


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 10, 2005 11:27 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
I have resolved my problem by adding "cascade=all" to the set :

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="hibernate.prov.model.Author" table="authors">

        <id name="id" column="id">
            <!-- The Author must have the same identifier as the Person -->
            <generator class="assigned"/>
        </id>

        <property name="alias"/>
        <one-to-one name="person" constrained="true"/>

        <set name="works" table="author_work" cascade="all">
            <key column="author_id"/>
            <many-to-many class="hibernate.prov.model.Work" column="work_id"/>
        </set>

    </class>
</hibernate-mapping>


But how should we do when the table "work" has its own primary key and a foreign key for the table "author" primary key (in the example, the table "work" has the same key of the "author" table) ?

I always get a JDBCException : "Duplicate key or integrity constraint violation message from server: "Column 'authorId' cannot be null"

Thank you in advance !
Regards
Lilian


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 10, 2005 9:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The Docs (and HIA) have a section on Parent Child relationships. Have a read as it has some very good information.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 11, 2005 5:50 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
david wrote:
The Docs (and HIA) have a section on Parent Child relationships. Have a read as it has some very good information.


Thank you for your answer.

I always have the doc at hand but dont have the time to read it entirely :-(

I have red the chapter 21 : Parent/Child example and have done the following :
- corrected my IParty.hbm.xml file (superclass of Worker) as follow :
Code:
<set
         name="contactPoints"
         inverse="true"
         cascade="all-delete-orphan" >
         
         <key column="partyId" not-null="true" />

         <one-to-many class="bab.admin.model.persistent.ContactPoint" />
         
      </set>


- added a method setParty to my ContactPoint class :
- edited my Worker addContactPoint method :
Code:
public void addContactPoint( ContactPoint contactPoint )
   {
      contactPoint.setParty( this );
      contactPoints.add( contactPoint );
   }


- added the many-to-one relation to my ContactPoint.hbm.xml :
Code:
<many-to-one
         name="party"
         column="partyId"
         not-null="true"
          />


But the problem is always "Duplicate key or integrity constraint violation message from server: "Cannot add or update a child row: a foreign key constraint fails"

Thank you for your help !
Best regards
Lilian

PS what is "HIA" ?

Hibernate version:
3.0
Mapping documents:
Worker.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
   <subclass
      name="bab.admin.model.persistent.Worker"
      discriminator-value="worker"
      extends="bab.admin.model.persistent.IParty" >
      
      <set
         name="specialities"
         table="t_workerspeciality"
         lazy="true"
         inverse="true"
         cascade="save-update"
         sort="unsorted" >

         <key column="partyId"></key>

         <many-to-many
            class="bab.admin.model.persistent.Speciality"
            column="specialityId"
            outer-join="auto" />

      </set>
      
      <join table="t_avs">
      
         <key column="partyId" />
         
         <component name="avs">

            <property name="cotise" column="cotiseYN" type="java.lang.Boolean"/>
            <property name="number" column="avsNumber" />
            <property name="requestDate" />
            <property name="expeditionDate" />
            <property name="receptionDate" />
            
         </component>
      </join>
      
      <join table="t_person">
      
         <key column="partyId" />
         
         <property name="sex" />
         <property name="title" />
         <property name="maritalStatus" column="maritalStatusCode" />
         <property name="birthdate" />
         <property name="accountInfo" />
         
         <component
            name="fullname"
            class="bab.admin.model.persistent.Fullname" >
            <property name="firstname" />
            <property name="lastname" />
         </component>
      </join>
      
      <join table="t_worker">
      
         <key column="partyId" />

         <property name="enabled" type="java.lang.Boolean" update="true"
            insert="true" access="property" column="enabledYN" not-null="false"
            unique="false" />
   
         <property name="critic" type="java.lang.String" update="true"
            insert="true" access="property" column="critic" not-null="false"
            unique="false" />
   
         <property name="compliment" type="java.lang.String"
            update="true" insert="true" access="property" column="compliment"
            not-null="false" unique="false" />
   
         <property name="motivationCode" type="java.lang.String"
            update="true" insert="true" access="property" column="motivationCode"
            not-null="true" unique="false" />
   
         <property name="motivationShortCode" type="java.lang.String"
            update="true" insert="true" access="property"
            column="motivationShortCode" not-null="true" unique="false" />
   
         <property name="affiliationDate" type="java.util.Date"
            update="true" insert="true" access="property"
            column="affiliationDate" not-null="true" unique="false" />
   
         <property name="lastReactivationDate" type="java.util.Date"
            update="true" insert="true" access="property"
            column="lastReactivationDate" not-null="false" unique="false" />
   
         <property name="workPermitCode" type="java.lang.String"
            update="true" insert="true" access="property" column="workPermitCode"
            not-null="true" unique="false" />
   
         <property name="authorizationExpirationDate"
            type="java.util.Date" update="true" insert="true" access="property"
            column="authorizationExpirationDate" not-null="false" unique="false" />
   
         <property name="source" type="java.lang.Boolean" update="true"
            insert="true" access="property" column="sourceYN" not-null="false"
            unique="false" />
            
         <many-to-one
            name="activity"
            column="activityId" />
      </join>
      
      <join table="t_workerDisponibility" >
         <key column="partyId" />
         
         <component
            name="disponibilities"
            class="bab.admin.model.persistent.Disponibility" >
         
            <property name="mondayMorning" column="mondayMorningYN" />
            <property name="mondayAfternoon" column="mondayAfternoonYN" />
            <property name="mondayNight" column="mondayNightYN" />
            <property name="tuesdayMorning" column="tuesdayMorningYN" />
            <property name="tuesdayAfternoon" column="tuesdayAfternoonYN" />
            <property name="tuesdayNight" column="tuesdayNightYN" />
            <property name="wednesdayMorning" column="wednesdayMorningYN" />
            <property name="wednesdayAfternoon" column="wednesdayAfternoonYN" />
            <property name="wednesdayNight" column="wednesdayNightYN" />
            <property name="thursdayMorning" column="thursdayMorningYN" />
            <property name="thursdayAfternoon" column="thursdayAfternoonYN" />
            <property name="thursdayNight" column="thursdayNightYN" />
            <property name="fridayMorning" column="fridayMorningYN" />
            <property name="fridayAfternoon" column="fridayAfternoonYN" />
            <property name="fridayNight" column="fridayNightYN" />
            <property name="saturdayMorning" column="saturdayMorningYN" />
            <property name="saturdayAfternoon" column="saturdayAfternoonYN" />
            <property name="saturdayNight" column="saturdayNightYN" />
            <property name="sundayMorning" column="sundayMorningYN" />
            <property name="sundayAfternoon" column="sundayAfternoonYN" />
            <property name="sundayNight" column="sundayNightYN" />
            
            <property name="february" column="februaryYN" />
            <property name="paques" column="paquesYN" />
            <property name="summer" column="summerYN" />
            <property name="autumn" column="autumnYN" />
            <property name="noel" column="noelYN" />
            <property name="jeunegenevois" column="jeunegenevoisYN" />
            <property name="ascension" column="ascensionYN" />
            <property name="pentecote" column="pentecoteYN" />
         </component>
      </join>
   </subclass>

</hibernate-mapping>


IParty.hbm.xml :
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
   <class name="bab.admin.model.persistent.IParty" table="t_party"
      dynamic-update="false" dynamic-insert="false"
      select-before-update="false" optimistic-lock="version">

      <id name="id" column="partyId" type="java.lang.Integer">
         <generator class="native">
         </generator>
      </id>

      <discriminator column="partyType" />

      <property name="comment" />

      <set
         name="contactPoints"
         inverse="true"
         cascade="all-delete-orphan" >
         
         <key column="partyId" not-null="true" />

         <one-to-many class="bab.admin.model.persistent.ContactPoint" />
         
      </set>


   </class>

</hibernate-mapping>



ContactPoint :
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
   <class name="bab.admin.model.persistent.ContactPoint" table="t_contactPoint"
      dynamic-update="false" dynamic-insert="false"
      select-before-update="false" optimistic-lock="version">

      <id name="id" column="contactPointId" type="java.lang.Integer">
         <generator class="native">
         </generator>
      </id>

      <discriminator column="contactType" />

      <property name="prefered"  column="primaryContactPointYN" not-null="true" />
      
      <many-to-one
         name="party"
         column="partyId"
         not-null="true"
          />
   </class>

</hibernate-mapping>


The method I use to save:
Code:
public void save( Collection workers ) throws InfrastructureException
   {
      try
      {
         Session session = HibernateUtil.currentSession();
         Transaction tx = session.beginTransaction();
         
         for ( Iterator iter = workers.iterator(); iter.hasNext(); )
         {
            Worker worker = (Worker)iter.next();
            session.save( worker );
         }
         tx.commit();
         HibernateUtil.closeSession();
      }
      catch ( HibernateException ex )
      {
         throw new InfrastructureException( ex );
      }
   }


Full stack trace of any exception that occurs:
bab.admin.model.exceptions.InfrastructureException: org.hibernate.exception.ConstraintViolationException: could not insert: [bab.admin.model.persistent.EmailContactPoint]
at bab.admin.model.dao.WorkersDAO.save(WorkersDAO.java:132)
at bab.admin.model.dao.WorkersDAOTests.testSaveOneWorker(WorkersDAOTests.java:43)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [bab.admin.model.persistent.EmailContactPoint]
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1790)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2192)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:238)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:158)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:416)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:153)
at org.hibernate.engine.Cascades.cascade(Cascades.java:721)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:860)
at org.hibernate.engine.Cascades.cascade(Cascades.java:739)
at org.hibernate.engine.Cascades.cascade(Cascades.java:817)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:361)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:263)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:158)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:429)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:424)
at bab.admin.model.dao.WorkersDAO.save(WorkersDAO.java:125)
... 14 more
Caused by: java.sql.SQLException: Duplicate key or integrity constraint violation message from server: "Cannot add or update a child row: a foreign key constraint fails"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1772)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1619)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1772)
... 42 more



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

The generated SQL (show_sql=true):
Hibernate: insert into t_party (comment, partyType) values (?, 'worker')
Hibernate: insert into t_avs (cotiseYN, avsNumber, requestDate, expeditionDate, receptionDate, partyId) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into t_person (sex, title, maritalStatusCode, birthdate, accountInfo, firstname, lastname, partyId) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into t_worker (enabledYN, critic, compliment, motivationCode, motivationShortCode, affiliationDate, lastReactivationDate, workPermitCode, authorizationExpirationDate, sourceYN, activityId, partyId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into t_workerDisponibility (mondayMorningYN, mondayAfternoonYN, mondayNightYN, tuesdayMorningYN, tuesdayAfternoonYN, tuesdayNightYN, wednesdayMorningYN, wednesdayAfternoonYN, wednesdayNightYN, thursdayMorningYN, thursdayAfternoonYN, thursdayNightYN, fridayMorningYN, fridayAfternoonYN, fridayNightYN, saturdayMorningYN, saturdayAfternoonYN, saturdayNightYN, sundayMorningYN, sundayAfternoonYN, sundayNightYN, februaryYN, paquesYN, summerYN, autumnYN, noelYN, jeunegenevoisYN, ascensionYN, pentecoteYN, partyId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into t_contactPoint (primaryContactPointYN, partyId, emailAddress, contactType) values (?, ?, ?, 'contact.type.email')
[/code]


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