Hi!
I have an address table and a department table. The department should have always one address. I insert first the address, after that i assign the address to the department, than i try to insert the department, but i've got an error saying that the addressid(department foreign key to address table) is null.
In debug i see that the address java object has the id set.....Please help me:) In the log one can see, that null is bind to the addressid in the
insert statement.....
<class
name="hibernate.generated.Tdepartment"
table="TDEPARTMENT"
>
<id
name="departmentid"
type="long"
column="DEPARTMENTID"
>
<generator class="increment" />
</id>
<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
unique="true"
length="50"
/>
<property
name="deptkeyname"
type="java.lang.String"
column="DEPTKEYNAME"
not-null="true"
unique="true"
length="50"
/>
<!-- associations -->
<!-- bi-directional many-to-one association to Taddress -->
<many-to-one
name="taddress"
class="hibernate.generated.Taddress"
not-null="true"
>
<column name="ADDRESSID" />
</many-to-one>
</class>
</hibernate-mapping>
The code goes:
Tdepartment dept = new Tdepartment();
dept.setDeptkeyname("Test1Dept");
dept.setName("Test1Dept");
Taddress addr = new Taddress();
addr.setStreet("Test12Street");
addOneAddress(addr);
dept.setTaddress(addr);
addOneDepartment(dept);
Exception:
Caused by: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544347. validation error for column ADDRESSID, value "*** null ***"
at org.firebirdsql.jdbc.AbstractPreparedStatement.internalExecute(AbstractPreparedStatement.java:445)
In the log:
2004-03-31 17:44:24,448 [ main - net.sf.hibernate.SQL ] DEBUG - insert into TDEPARTMENT (NAME, DEPTKEYNAME, PARENTDEPTID, ADDRESSID, DEPARTMENTID) values (?, ?, ?, ?, ?)
Hibernate: insert into TDEPARTMENT (NAME, DEPTKEYNAME, PARENTDEPTID, ADDRESSID, DEPARTMENTID) values (?, ?, ?, ?, ?)
2004-03-31 17:44:24,448 [ main - net.sf.hibernate.impl.BatcherImpl ] DEBUG - preparing statement
2004-03-31 17:44:24,448 [ main - net.sf.hibernate.persister.EntityPersister ] DEBUG - Dehydrating entity: [ifx.cim.backend.hibernate.generated.Tdepartment#1]
2004-03-31 17:44:24,448 [ main - net.sf.hibernate.type.StringType ] DEBUG - binding 'Test1Dept' to parameter: 1
2004-03-31 17:44:24,448 [ main - net.sf.hibernate.type.StringType ] DEBUG - binding 'Test1Dept' to parameter: 2
2004-03-31 17:44:24,448 [ main - net.sf.hibernate.type.LongType ] DEBUG - binding null to parameter: 3
2004-03-31 17:44:24,448 [ main - net.sf.hibernate.type.LongType ] DEBUG - binding null to parameter: 4
2004-03-31 17:44:24,448 [ main - net.sf.hibernate.type.LongType ] DEBUG - binding '1' to parameter: 5
2004-03-31 17:44:24,464 [ main - net.sf.hibernate.impl.BatcherImpl ] DEBUG - done closing: 0 open PreparedStatements, 0 open ResultSets
2004-03-31 17:44:24,464 [ main - net.sf.hibernate.impl.BatcherImpl ] DEBUG - closing statement
2004-03-31 17:44:24,464 [ main - net.sf.hibernate.util.JDBCExceptionReporter ] DEBUG - SQL Exception
|