-->
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: Problems saving an unidirectional OneToMany relation
PostPosted: Tue Feb 15, 2011 4:22 am 
Newbie

Joined: Tue Feb 15, 2011 4:19 am
Posts: 2
I have a problem, persisting a unidirectional onetomany relation.

Here is the code:

Code:
@Entity
public class Customer extends Person {

    @Id
    @GeneratedValue
    protected Long id;
   
    ...

    @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(
        name = "customer_addressList",
        joinColumns = @JoinColumn(name = "customer_id", referencedColumnName = "id"),
        inverseJoinColumns = @JoinColumn(name = "address_id", referencedColumnName = "id")
    )
    protected List<Address> addressList;

}


@Entity
public class Address extends BaseEntity {

    @Id   
    @GeneratedValue
    protected Long id;
   
    ...
}



When I create a new customer with a new addresse and persist it to the database, then the the customer and the address is saved to the database, but there is no entry in the table "customer_addressList".

When I first save the new customer to the database and then add the new (not persistent) address to the customer an update the customer, then the address will be saved and there is a new entry in the table customer_addressList.

Whats wrong by saving a new customer with a new address to the same time?


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.