-->
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: Parent/child insert pb with CHECK CONSTRAINT
PostPosted: Tue Jun 24, 2008 10:09 am 
Newbie

Joined: Mon Mar 10, 2008 3:07 am
Posts: 7
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 4:00 am 
Newbie

Joined: Mon Mar 10, 2008 3:07 am
Posts: 7
Anybody have any idea ?

Do you think it's ans Hibernate probleme (i don't think), an implementation problem or a DB/connection pb ?

thx for your help


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 5:33 pm 
Newbie

Joined: Mon Mar 10, 2008 3:07 am
Posts: 7
solution found !!!

In my DAOJpa layer i've written :

Code:
@PersistenceContext[b](type = PersistenceContextType.EXTENDED)[/b]
private EntityManager em;


instead of :
Code:
@PersistenceContext
private EntityManager em;


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 27, 2008 10:03 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Thanks for posting back!

Even though it may seem like you're having a conversation with yourself, this thread will invariably help someone else who is running into the same problem.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.