I have two classes, Patient and Report. In patient, there is a collection of Reports. Reports doesn't know about Patient, so the association is Unidirectional.
This is my mapping file definition for the Patinet object, Patient.hbm.xml
<bag name="reports" table="Report" cascade="all">
<key column="patientId"/>
<one-to-many class="com.orchestral.cdr.element.Report"/>
</bag>
and I've done it according to the documentation. However when I persist the patient object, it fails to write any child objects because it can't write the foreign key to the Reports table. The foreign-key is set to NOT-NULL, so it must write a value in that column. It keeps generating the below exception trace.
Am I missing something??? Please assist.
[b]Hibernate version:2.1.4 [/b]
[b]Mapping documents:
<bag name="reports" table="Report" cascade="all">
<key column="id"/>
<one-to-many class="com.orchestral.cdr.element.Report"/>
</bag>
[/b]
[b]Code between sessionFactory.openSession() and session.close():[/b]
[b]Full stack trace of any exception that occurs:
net.sf.hibernate.JDBCException: could not insert: [com.orchestral.cdr.element.Report#1]
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:478)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.orchestral.cdr.CDRDBBaseImpl.persist(CDRDBBaseImpl.java:285)
at com.orchestral.cdr.element.PersistReportTest.testReportPersistence(PersistReportTest.java:50)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:166)
at junit.framework.TestCase.runBare(TestCase.java:140)
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:131)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: java.sql.SQLException: [CONTRACT1]Cannot insert the value NULL into column 'patientID', table 'CDRAaron.dbo.Report'; column does not allow nulls. INSERT fails.
at com.inet.tds.e.a(Unknown Source)
at com.inet.tds.e.a(Unknown Source)
at com.inet.tds.b.int(Unknown Source)
at com.inet.tds.b.executeUpdate(Unknown Source)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
... 20 more
[/b]
[b]Name and version of the database you are using:SQL Server 2000[/b]
[b]The generated SQL (show_sql=true):
Hibernate: insert into Patient (mothersMaidenNameString, sex, addressString, countyCode, homePhoneString, businessPhoneString, socialSecurityNumber, mothersIdentifierString, birthPlace, multipleBirthIndicator, birthOrder, patientDeathIndicator, dateOfBirth, patientDeathDate, livingDependency, livingArrangement, primaryFacilityName, primaryFacilityNameTypeCode, primaryFacilityNameRepresentationCode, primaryFacilityString, studentIndicator, handicap, livingWill, organDonor, separateBill, protectionIndicator, primaryFacilityID, driversLicenseNumber, issuingState, expiryDate, assigningAuthorityNamespaceID, assigningAuthorityUniversalID, assigningAuthorityUniversalIDType, medicalRecordNumber, checkDigit, checkDigitSchemeCode, identifierTypeCode, assigningFacilityNamespaceID, assigningFacilityUniversalID, assigningFacilityUniversalIDType, address, mothersMaidenName, homePhone, businessPhone, mothersIdentifier, patientAccountNumber, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Report (id) values (?)
[/b]
[b]Debug level Hibernate log excerpt:[/b]
|