-->
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.  [ 1 post ] 
Author Message
 Post subject: @OneToOne
PostPosted: Thu Oct 16, 2008 7:29 am 
Newbie

Joined: Tue Jul 25, 2006 2:50 pm
Posts: 1
Hello,

I have a question about how to use the one to one annotation and ensure that children are deleted when the parent is updated.


Hibernate version:

hibernate-core 3.3.1.GA
hibernate-annotations 3.4.0.GA
hibernate-commons-annotations 3.1.0.GA





My test classes:


Code:

@Entity
public class Person {

    @Id
    private String id = UUID.randomUUID().toString();

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = Address.class)
    @Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private Address address;

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }
}

@Entity
public class Address {

    @Id
    private String id = UUID.randomUUID().toString();
}




Example usage:

Code:

Person person = new Person();
        Address address = new Address();
        person.setAddress(address);

        session.save(person);

        person.setAddress(null);

        session.update(person);



When i check the db i find that there is still a row in the address table.

Any ideas what I can do to solve this?

Regards

Ben Short


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

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.