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
|