jpa controller entity relation problem

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

jpa controller entity relation problem

blob84
I have generated entity classes and jpa controller from database.
I have two classes

Code:
@Entity
@Table(name = "parent")
@XmlRootElement
public class Parent implements Serializable {

 private static final long serialVersionUID = 1L;
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Basic(optional = false)
 @Column(name = "id")
 private Integer id;
 @OneToOne(cascade = CascadeType.ALL, mappedBy = "parent")
 private Child child;

 public Parent() {
 }
    etc....
}


@Entity
@Table(name = "child")
@XmlRootElement
public class Child implements Serializable {

  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @Column(name = "parent_id")
  private Integer parentId;
  @JoinColumn(name = "parent_id", referencedColumnName = "id", insertable = false, updatable = false)
  @OneToOne(optional = false)
  private Parent parent;
  public Child() {
  }
  etc....
 }



When I destroy the parent If the child is not destroyed I get an exception because of the relation, so I need to destroy the child before to destroy the parent but Cascade.ALL is enabled, it should already be done.
How to solve?