-->
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: UserType and cascade
PostPosted: Fri Jul 21, 2006 3:15 am 
Newbie

Joined: Sat Feb 19, 2005 1:34 am
Posts: 5
Hi,

i've implemented a UserType to do some custom persitence and it works nicely.

However, the item that is persisted using this type holds onto objects that are persisted using the normal Hibernate mapping approach. So my referenced objects aren't getting persisted.

How do I cascade?

I have this sort of thing:

<property name="children" type="MyNodeChildrenUserType" column="children" not-null="false"/>

I want to add a cascade attribute here so that after my UserType is run to persist the 'children' , I can cascade the save to the objects referenced by the children.

I've tried doing this in my UserType and it doesnt work:

public void nullSafeSet(
PreparedStatement inPreparedStatement,
Object o,
int i)
throws HibernateException, SQLException {
StringBuffer strKids = new StringBuffer();
MyNodeChildren kids = (MyNodeChildren)o;
if(kids!=null){
List<MyNode> children = kids.toList();
for(MyNode node : children){
strKids.append(node.getId());
strKids.append(",");

// I TRIED THIS WITHOUT SUCCESS
Session session = sessionFactory.getSession();
Transaction tx = session.beginTransaction();
session.save(node);
tx.commit();
}
strKids = strKids.delete(strKids.length()-1, strKids.length());
}
String val = null;
if(strKids!=null && strKids.length()>0){
val = strKids.toString();
}
inPreparedStatement.setString(i, val);
}

cheers


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.