Hi,
After reading documentation & searching accross this forum i can't found any solution to my simple, i thought, problem.
My environement :
JAVA 6 + Spring 2.5.2
Hibernate EntityManager 3.3.1
Hibenrate Annotation 3.3.0
SGBD SQL Server 2005 Express
And I use pattern Session-per-thread in webApp.
My problem : i want create and persist a Parent object and after that (in the same transaction) a Child object wich reference the parent.
The first INSERT statement is ok but the second one never finish (database never terminate the communication).
Parent object :
Code:
@Entity
public class OTree implements Serializable {
private static final long serialVersionUID = -7352681804966025088L;
@Version
private int version = 0;
@Id
@GeneratedValue
private Long id;
}
Child Object :
Code:
@Entity
public class OTree implements Serializable {
private static final long serialVersionUID = -2484398041377182745L;
@Version
private int version = 0;
@Id
@GeneratedValue
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private OTree oTree;
}
Controller code :
Code:
@Transactional
public void test_oTreeInsert() {
OTree oTree = new OTree();
oTree = this.orgManager.insertOrUpdateOTree(oTree);
ONode oNode = new ONode();
oNode.setOTree(oTree);
oNode = this.orgManager.insertOrUpdateONode(oNode);
// -->.<-- [b]execution stop here[/b]
}
Service (orgManager) code :
Code:
@Service
@Transactional
public class OrgManagerImpl extends BaseManagerImpl implements OrgManager {
// some other code
public OTree insertOrUpdateOTree(OTree oTree) {
return this.oTreeDAO.makePersistent(oTree);
}
public ONode insertOrUpdateONode(ONode oNode) {
return this.oNodeDAO.makePersistent(oNode);
}
}
"oTreeDAO.makePersistent" and "oNodeDAO.makePersistent" just do merge on EntityManager with the passed object.
SQL trace :
Code:
2008-06-24 13:27:16,906 DEBUG [org.hibernate.SQL] - <insert into OTree (holder_id, name, root_id, version) values (?, ?, ?, ?)>
2008-06-24 13:27:16,968 DEBUG [org.hibernate.SQL] - <insert into ONode (oTree_id, ou_id, parent_id, version) values (?, ?, ?, ?)>
My DB schema :
Code:
create table OTree (
id numeric(19,0) identity not null,
version int not null,
primary key (id)
);
create table ONode (
id numeric(19,0) identity not null,
version int not null,
oTree_id numeric(19,0) not null,
primary key (id)
);
alter table ONode add constraint FK47E62F125161157 foreign key (oTree_id) references OTree;
If I remove the foreign key all is ok, but with it the second insert never terminate.
My case is simple so I can't imagine that it's an hibernate problem. Anybody see where i've made a mistake ?
Thanks
PHaroZ, an hibernate beginer.