simple (?) hibernate problem: two classes

P

Pawel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top