-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate collection v/s Java collection in SLSB
PostPosted: Tue Apr 25, 2006 7:57 am 
Newbie

Joined: Fri Feb 03, 2006 1:40 am
Posts: 11
I have a peice of code such as below that runs in a SLSB. I have setup the hibernate properties
to use the session/transaction of the container (weblogic)


//SLSB EJB method
Test1 persistTest1 (Test1 t1) {
if (t1.getId() == null) { //if its a "new" Test1 ----------------------------------(4)
so reset all attribute ids to null...
for (Attrib fa : t1.getAttributes()) {
fa.setId(null);
}

HibernateUtil.getCurrentSession().save(t1);
return t1;
}
}


where "id" is the object-id of Test1

This tries to save a 1:n relationship between Test1 and its Attribs that are declared
as cascade=all,delete-orphan in Test1

Now in the client, I am doing the following

.... create Test1 t1 and add some attributes.. Then,

Test1 t1 = persistTest1(t1);--------------(1)
t1.setId(null); --------------(2)
t1 = persistTest1(t1);-------------(3)

The reason for (2) is so that I can treat t1 as a brand new Test1 (like a "Save As" functionality)
However I get a d/b rollback and an exception in the backend when (3) gets executed.

In the backend when I "replace" the collection as generated by Hibernate in (1)
with a java collection as shown below, everything runs fine.

Test1 persistTest1 (Test1 t1) {
if (t1.getId() == null) { ----------------------------------(4)
//treat it as a new t1, so reset all attribute ids as well...
for (Attrib fa : t1.getAttributes()) {
fa.setId(null);
}

------------>
List<Attrib> l = new ArrayList<Attrib>();
l.addAll(t1.getAttributes());
t1.setAttributes(l);
------------>
HibernateUtil.getCurrentSession().save(t1);
return t1;
}
}

Any clues ?

Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.