-->
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.  [ 6 posts ] 
Author Message
 Post subject: how to save only child object
PostPosted: Wed Sep 02, 2009 5:58 am 
Newbie

Joined: Fri Jul 17, 2009 1:00 am
Posts: 5
Hi All,
I have two tables one is "Author" and "Book".

Here only one-to-many unidirectional mapping is there.
Author--------------->Book

Author id is there in Book table as a foreign key with not null field. and book have his own id.

First time i saved successfully with Author as well as Book.
From second time onwards i need to save only Book object( not Author object) by using reference id.

How to save only child Object?.

If u have any example please send it to me.


Thanks & Regards,
Srinivas,
seenuindia555@gmail.com


Top
 Profile  
 
 Post subject: Re: how to save only child object
PostPosted: Wed Sep 02, 2009 6:38 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
The easy way is to simply load the child object, not the parent or containing object. Make sure it's loaded in a lazy fashion, and there will be no update to the containing object.

But if the containing object changes, why wouldn't you want to update it? In fact, it almost sounds like a flaw in the design?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: how to save only child object
PostPosted: Wed Sep 02, 2009 7:12 am 
Newbie

Joined: Fri Jul 17, 2009 1:00 am
Posts: 5
When i'm trying to save the child object i got this error.

org.hibernate.PropertyValueException: not-null property references a null or transient value: Book._booksBackref
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at AuthorManager.main(AuthorManager.java:32)


What i need to do for this error.


Top
 Profile  
 
 Post subject: Re: how to save only child object
PostPosted: Wed Sep 02, 2009 7:25 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 5:28 am
Posts: 42
i think u r having bi-directional association.In ur Child Object u have a not-nullable Instance variable of Parent
then how u will save a Object without value for not-nullable column.
i think u should load the parent then update u r child.

_________________
Warm Regards,
Tarun Walia


Top
 Profile  
 
 Post subject: Re: how to save only child object
PostPosted: Wed Sep 02, 2009 6:15 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Looks like you're going to have to make that back reference nullable in the database.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: how to save only child object
PostPosted: Thu Sep 03, 2009 1:05 am 
Newbie

Joined: Fri Jul 17, 2009 1:00 am
Posts: 5
Can u tell me how to resolve "bakref" problem.


Thanks & Regards,
Srinivas


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

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.