simple (?) hibernate problem: two classes

Discussion in 'Java' started by Pawel, Sep 18, 2007.

  1. Pawel

    Pawel Guest

    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
     
    Pawel, Sep 18, 2007
    #1
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ilias Lazaridis
    Replies:
    0
    Views:
    1,987
    Ilias Lazaridis
    Dec 27, 2004
  2. Replies:
    0
    Views:
    4,150
  3. Replies:
    9
    Views:
    456
    Sion Arrowsmith
    Aug 10, 2006
  4. GenxLogic
    Replies:
    3
    Views:
    1,969
    andrewmcdonagh
    Dec 6, 2006
  5. jstorta
    Replies:
    1
    Views:
    12,265
  6. RC
    Replies:
    0
    Views:
    548
  7. Eleanna Skouta
    Replies:
    2
    Views:
    9,214
    Arne Vajhøj
    Dec 9, 2008
  8. Amit Jain
    Replies:
    7
    Views:
    3,783
    Amit Jain
    Apr 27, 2009
Loading...