Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > simple (?) hibernate problem: two classes

Reply
Thread Tools

simple (?) hibernate problem: two classes

 
 
Pawel
Guest
Posts: n/a
 
      09-18-2007
Hi,

I have a strange problem - I can't find a solution however I guess it
is rather common.

I have two classes: Person and RegistrationAddress. A Person has a
RegistrationAddress:

<class name="org.dyndns.orzekanie.Person" table="PERSONS">
<id name="id">
<generator class="native"/>
</id>
<property name="firstName" column="FIRST_NAME"/>
....
<many-to-one name="address"
class="org.dyndns.orzekanie.RegistrationAddress" lazy="false"
cascade="all" column="ADDRESS_ID"/>
</class>

Sometimes the address for person should be null - there is no address
at all. I would like Hibernate to make possible to delete this address
from database in some way of this:

person.address = null;
hibernateSession.update(person);

The person is a transient object. The foreign key ADDRESS_ID in the
table PERSONS can be null.
I believed that person's address should be automatically deleted from
a database when object address is null and session is updated - but I
get a NullPointerException. I'm wondering how should I tell hibernate
to remove my address when person.address is null and session is
updated.

I'm using hibernate 3.2.4, java 1.5.0_12 and MySQL 4.1.22.

I would be very grateful for any advices,

Pawel

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hibernate LazyInitializationException in web application Struts asMVC, Spring as IOC and Hibernate as ORM layer Amit Jain Java 7 04-27-2009 10:27 AM
HIBERNATE - java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration Eleanna Skouta Java 2 12-09-2008 02:09 AM
Hibernate cannot find hibernate.cfg.xml jstorta Java 1 01-19-2008 01:45 PM
Hibernate Syncronizer now generates code for Hibernate 3.0 msenin@covad.net Java 0 07-14-2005 05:47 AM
[HIBERNATE] [EVALUATION] - Gavin King Censors Hibernate Forum Ilias Lazaridis Java 0 12-27-2004 04:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57