-->
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: Hibernate OneToMany with ORA-02291 error
PostPosted: Fri Aug 21, 2015 4:47 am 
Newbie

Joined: Fri Aug 21, 2015 4:40 am
Posts: 1
Hi,
I have a problem when persist an entity with its childs in OneToMany relationship. Here my two entity:
Code:
@Entity
@Table(name="USER")
public class User implements Serializable {
  ...
  @Id
  @Column(name="ID_USER")
  private String idUser;

  @OneToMany(mappedBy="user", cascade=CascadeType.PERSIST)
  private List<Address> address;

  public List<Address> getAddress() {
     return this.address;
  }

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

  public Address addAddress(Address address) {
     getAddress().add(address);
     address.setUser(this);

     return address;
  }

  public Address removeAddress(Address address) {
     getAddress().remove(address);
     address.setUser(null);

     return address;
  }
  ...
}

@Entity
@Table(name="ADDRESS")
public class Address implements Serializable {
    ...
   @EmbeddedId
   private AddressPK id;
   
    @ManyToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name="ID_USER", insertable=false, updatable=false, nullable=false)
    private User user;

    public User getUser() {
        return this.user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}

@Embeddable
public class AddressPK implements Serializable {
   ...
   @Column(name="ID_USER", insertable=false, updatable=false)
   private String idUser;
   ...
}


And now the persist operation that generate ORA-02291 error:

Code:
User u = new User();
u.setAddress(new ArrayList<Address>());

u.set...

Address a1 = new Address();
a1.set...
u.addAddress(a1);

Address a2 = new Address();
a2.set...
u.addAddress(a2);

entityManager.persist(u);


What can i do to fix the problem?

Thanks to everyone!


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.