hello,
i'm in trouble with embeddable classes which has
OneToOne relation with CascadeType.PERSIST + orphanRemoval=true.
Entity classes:
@Entity
public class NewEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Embedded
private NewEntityEE neee = new NewEntityEE();
}
@Embeddable
public class NewEntityEE implements Serializable {
@OneToOne(cascade = {CascadeType.PERSIST}, orphanRemoval = true)
@JoinColumn(nullable = false)
private NewEntity3 ne3 = new NewEntity3();
}
@Entity
public class NewEntity3 implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
the Service class:
@Stateless
public class NewEJB {
@PersistenceContext
private EntityManager em;
public NewEntity create(){
NewEntity ne = new NewEntity();
em.persist(ne);
return ne;
}
}
when i invoke NewEJB#create(),
i expected to execute INSERT of NewEntity3 before NewEntity,
but INSERT of NewEntity has executed first.
exception snippet below :
UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [50, SEQ_GEN]
SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
bind => [SEQ_GEN]
INSERT INTO NEWENTITY (ID, NE3_ID) VALUES (?, ?)
bind => [1, 2]
VALUES(1)
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ...
in addition, when i remove orphanRemoval=true statement of
OneToOne annotation in NewEntityEE, it worked as i expected.
Is this behavior as the JPA specification?
thanks.