Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: optional many-to-one in hibernate
PostPosted: Fri Dec 12, 2008 6:21 am 
Beginner
Beginner

Joined: Mon Dec 17, 2007 11:08 pm
Posts: 47
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

_________________
happy hacking !


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.