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
|