hi, i have a class like this.
Code:
public class User {
private HomePage home;
private OtherPage other;
//getter and setter here
}
public abstract class Page
{
//some property
}
public class HomePage extends Page //other page
{
//some property
}
Code:
<many-to-one name="homePage"
column="homePage_id"
unique="true"
not-null="true" cascade="all"/>
when i try to save user like this:
Code:
User user = new User();
HomePage page = new HomePage();
user.setHomePage(page);
session.save(user); //throw exception :not-null property references a null or transient value
this is because of unsave page entity/instance
i need to include this line before save user :
Code:
session.save(page);
My question is why cascade not working ? is that any way to save the page instance as well when save user ? (both is new instance)
is that anyway to make "page" optional in many-to-one to user ??
when i modify the object, it alway create a new object and insert into table but left the old instance in table. ( i wanna just update the instance without create a new one row). how can i do it ?
kiwi