-->
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.  [ 4 posts ] 
Author Message
 Post subject: Firebird 1.5 many-to-one relation problem once again:(
PostPosted: Thu Apr 01, 2004 3:27 am 
Newbie

Joined: Mon Sep 08, 2003 12:37 pm
Posts: 10
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 bound to the addressid in the
insert statement.....

The whole thing has worked under MySQL!!!!

<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); //this inserts the address and commits
dept.setTaddress(addr);
addOneDepartment(dept); //this inserts a department and commits

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 7:46 am 
Newbie

Joined: Mon Sep 08, 2003 12:37 pm
Posts: 10
I'm very surprised not getting any answer for the above problem. Should i paste more info? I thought it's something very simple that should work without any problems with Hibernate...

Once again my problem:

I have Department table which has a not null foreign key relation to the Address table. I insert first an address record and i assigne it to the department. When i want to insert the department, null is bound against the foreignkey column (please see above the log info).

How should this work? What i'm missig? Please help!!! The whole thing was working under MySQL, now i'm using Firebird1.5.

Thank you..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 4:26 am 
Newbie

Joined: Mon Sep 08, 2003 12:37 pm
Posts: 10
I investigated further this problem:

I wrote a test case:

public void testDepartment()
{
try
{
removeAllDepartments();
removeAllAddresses();
addAllDepartments();
}
catch (DAOException e)
{
e.printStackTrace();
fail();
}
catch (Exception e)
{
e.printStackTrace();
fail();
}
}
private void addAllDepartments() throws DAOException
{
Tdepartment dept = new Tdepartment();
dept.setDeptkeyname("Test1Dept");
dept.setName("Test1Dept");

Taddress addr = new Taddress();
addr.setStreet("Test12Street");

//set foreign key relation
addr.setTdepartments(new HashSet());
addr.getTdepartments().add(dept);
dept.setTaddress(addr);

//add the address
addOneAddress(addr);
//add the department
addOneDepartment(dept);
}

private void addOneDepartment(Tdepartment dept) throws DAOException
{
IDepartmentDAO daoMan =
(IDepartmentDAO)GlobalDAOFactory.getIDAOFactory().getDAOInstance(
IDepartmentDAO.class);
daoMan.add(dept);
Tdepartment addedDept = findDepartmentByName(dept.getName());
assertNotNull(addedDept);
assertEquals(dept.getName(), addedDept.getName());
}

private void addOneAddress(Taddress address) throws DAOException
{
IAddressDAO daoMan =
(IAddressDAO)GlobalDAOFactory.getIDAOFactory().getDAOInstance(
IAddressDAO.class);
daoMan.add(address);
}

private void removeAllDepartments() throws Exception
{
IDepartmentDAO daoMan =
(IDepartmentDAO)GlobalDAOFactory.getIDAOFactory().getDAOInstance(
IDepartmentDAO.class);
Collection departments = daoMan.findAll();
if (departments.size() > 0)
{
for (Iterator iter = departments.iterator(); iter.hasNext();)
{
Tdepartment department = (Tdepartment)iter.next();
daoMan.remove(department);
}
departments = daoMan.findAll();
assertEquals(0, departments.size());
}
}

private void removeAllAddresses() throws Exception
{
IAddressDAO daoMan =
(IAddressDAO)GlobalDAOFactory.getIDAOFactory().getDAOInstance(
IAddressDAO.class);
Collection addresses = daoMan.findAll();
if (addresses.size() > 0)
{
for (Iterator iter = addresses.iterator(); iter.hasNext();)
{
Taddress address = (Taddress)iter.next();
daoMan.remove(address);
}
addresses = daoMan.findAll();
assertEquals(0, addresses.size());
}
}

My DAO objects simply by add and delete are starting the transaction and at the end they commit or rollback depending on successfull add/delete or not(if exception is thrown rollback is made, for session management threadlocal is used).

When my tables are empty everything goes fine! But running the second time the test, i got the error (see above). I delete everything from my tables, than once again everything goes fine. What i'm missing there? Why do i get the above error if the tables were populated with data?

(if i run only the delete part of the test, the tables are deleted correctly).

Could someone clearify this for me, please!!!!!

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 10:35 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
Did you ever resolve your problem? I've got the same issue.

The first role I insert works fine but the second one has problems. The table isn't that complicated. I can insert the SQL using isql without problem.


Code:
00:28:12,234 DEBUG - insert into SVD_ROLE (RoleName, Description, SystemRole, RoleId) values (?, ?, ?, ?)
00:28:12,250 DEBUG - binding 'User' to parameter: 1
00:28:12,250 DEBUG - binding 'Standard role assigned to general users' to parameter: 2
00:28:12,250 DEBUG - binding 'false' to parameter: 3
00:28:12,250 DEBUG - binding '1' to parameter: 4
00:28:12,250 DEBUG - insert into SVD_ROLEACCESSRIGHTS (RoleId, RightId) values (?, ?)
00:28:12,250 DEBUG - binding '1' to parameter: 1
00:28:12,265 DEBUG - binding 'USE_WEBDAV' to parameter: 2
00:28:12,265 DEBUG - binding '1' to parameter: 1
00:28:12,265 DEBUG - binding 'RENAME_MY_FILE' to parameter: 2
00:28:12,265 DEBUG - binding '1' to parameter: 1
00:28:12,265 DEBUG - binding 'SEND_MESSAGE' to parameter: 2
00:28:12,265 DEBUG - binding '1' to parameter: 1
00:28:12,265 DEBUG - binding 'RENAME_FOLDER' to parameter: 2
00:28:12,265 DEBUG - binding '1' to parameter: 1
00:28:12,265 DEBUG - binding 'CREATE_FOLDER' to parameter: 2
00:28:12,281 DEBUG - binding '1' to parameter: 1
00:28:12,281 DEBUG - binding 'CHANGE_MY_GROUP' to parameter: 2
00:28:12,281 DEBUG - binding '1' to parameter: 1
00:28:12,281 DEBUG - binding 'REVISE_MY_DOCUMENT' to parameter: 2
00:28:12,281 DEBUG - binding '1' to parameter: 1
00:28:12,281 DEBUG - binding 'EXPORT_IMPORT_VERS' to parameter: 2
00:28:12,281 DEBUG - binding '1' to parameter: 1
00:28:12,296 DEBUG - binding 'CREATE_DOCUMENT' to parameter: 2
00:28:12,296 DEBUG - binding '1' to parameter: 1
00:28:12,296 DEBUG - binding 'MODIFY_MY_USER_DETAILS' to parameter: 2
00:28:12,296 DEBUG - binding '1' to parameter: 1
00:28:12,296 DEBUG - binding 'VIEW_DOCUMENT' to parameter: 2
00:28:12,296 DEBUG - binding '1' to parameter: 1
00:28:12,312 DEBUG - binding 'RETIRE_FOLDER' to parameter: 2
00:28:12,312 DEBUG - binding '1' to parameter: 1
00:28:12,312 DEBUG - binding 'RETIRE_MY_DOCUMENT' to parameter: 2
00:28:12,343 DEBUG - insert into SVD_ROLE (RoleName, Description, SystemRole, RoleId) values (?, ?, ?, ?)
00:28:12,343 DEBUG - binding 'Guest' to parameter: 1
00:28:12,343 DEBUG - binding 'Guest role for viewing documents only' to parameter: 2
00:28:12,343 DEBUG - binding 'false' to parameter: 3
00:28:12,343 DEBUG - binding '2' to parameter: 4
00:28:12,406 ERROR - GDS Exception. 335544347. validation error for column ROLEID, value "*** null ***"
00:28:12,406 ERROR - GDS Exception. 335544347. validation error for column ROLEID, value "*** null ***"
00:28:12,421 ERROR - Could not execute JDBC batch update
java.sql.BatchUpdateException: GDS Exception. 335544347. validation error for column ROLEID, value "*** null ***"
   at org.firebirdsql.jdbc.AbstractPreparedStatement.executeBatch(AbstractPreparedStatement.java:578)
   at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2385)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
   at com.avalon.seaview.domain.Role.newRole(Role.java:185)
   at com.avalon.seaview.domain.Role.createStandardRoles(Role.java:125)
[/code]


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