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
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