-->
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: OneToMany relationship, controlled by the parent, and not nu
PostPosted: Wed Jan 06, 2010 3:04 pm 
Newbie

Joined: Wed Jan 06, 2010 3:26 am
Posts: 2
What ever i try, i can't get it to work...please help.

<hibernate-mapping>
<class name="StamTabel" table="STAMTABEL">
<id name="id" column="ST_ID" type="long" >
<generator class="sequence"/>
</id>

<list name="stamDataDictionaries" inverse="true" cascade="all">
<key column="ST_ID" />
<index column="SD_VOLGNUMMER" />
<one-to-many class="StamDataDictionary" />
</list>

<property name="naam" column="ST_NAAM" not-null="true" unique="true" />
<property name="omschrijving" column="ST_OMSCHRIJVING" not-null="true" unique="true" />
<property name="datumUpload" column="ST_DATUMTIJD_UPLOAD" not-null="true" unique="true" type="timestamp" />

</hibernate-mapping>

<hibernate-mapping>
<class name="StamDataDictionary" table="STAMDATADICTIONARY">
<composite-id >
<key-property name="stamTabelId" column="ST_ID" type="big_integer" />
<key-property name="volgnummer" column="SD_VOLGNUMMER" type="integer"/>
</composite-id>

<many-to-one name="stamtabel" class="StamTabel" column="ST_ID" not-null="true" update="false" insert="false" cascade="all"/>

<property name="naam" column="SD_NAAM" not-null="true" />
<property name="datatype" column="SD_DATATYPE" not-null="true" />
<property name="lengte" column="SD_LENGTE" not-null="true" />

</class>

</hibernate-mapping>

Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();

StamTabel stamtabel = new StamTabel();
stamtabel.setNaam("Naam");
stamtabel.setDatumUpload(new Date());
stamtabel.setOmschrijving("Een omschrijving");

StamDataDictionary stamdd = new StamDataDictionary();
stamdd.setVolgnummer(Integer.valueOf(1));
stamdd.setNaam("Kolom naam");
stamdd.setDatatype("String");
stamdd.setLengte(Integer.valueOf(15));

stamtabel.addStamDataDictionary(stamdd);

Long msgId = (Long) session.save(stamtabel);

tx.commit();
session.close();

DEBUG - SQL -
insert
into
STAMDATADICTIONARY
(SD_NAAM, SD_DATATYPE, SD_LENGTE, ST_ID, SD_VOLGNUMMER)
values
(?, ?, ?, ?, ?)
Hibernate:
insert
into
STAMDATADICTIONARY
(SD_NAAM, SD_DATATYPE, SD_LENGTE, ST_ID, SD_VOLGNUMMER)
values
(?, ?, ?, ?, ?)
DEBUG - AbstractBatcher - preparing statement
DEBUG - AbstractEntityPersister - Dehydrating entity: [StamDataDictionary#component[stamTabelId,volgnummer]{stamTabelId=null, volgnummer=1}]
DEBUG - AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - AbstractBatcher - closing statement
DEBUG - JDBCExceptionReporter - could not insert: [StamDataDictionary] [insert into STAMDATADICTIONARY (SD_NAAM, SD_DATATYPE, SD_LENGTE, ST_ID, SD_VOLGNUMMER) values (?, ?, ?, ?, ?)]
java.sql.SQLException: Attempt to insert null into a non-nullable column: column: ST_ID table: STAMDATADICTIONARY in statement [insert into STAMDATADICTIONARY (SD_NAAM, SD_DATATYPE, SD_LENGTE, ST_ID, SD_VOLGNUMMER) values (?, ?, ?, ?, ?)]


I tried every example from book, tutorials etc...but in any examples there has the child table a primarykey of 2 colums. ST_ID is the Foreignkey form STAMTABEL and ST_VOLGNUMMER is a generated value by the application.

Please can somebody help me??

Regards,

Jeroen


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.