Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @Embedded with CascadeType.PERSIST + orphanRemoval = true
@Embedded with CascadeType.PERSIST + orphanRemoval = true [message #838931] Sat, 07 April 2012 22:38 Go to next message
kyle shanahan is currently offline kyle shanahanFriend
Messages: 2
Registered: April 2012
Junior Member
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.
Re: @Embedded with CascadeType.PERSIST + orphanRemoval = true [message #840030 is a reply to message #838931] Mon, 09 April 2012 15:29 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I am not sure how this would occur unless it is associated to an existing NewEntity3 instance. Can you set logging to finest using <property name="eclipselink.logging.level" value="FINEST"/> to see what might be happening? Are there any other mappings using the "NE3_ID" field?

Best Regards,
Chris

Re: @Embedded with CascadeType.PERSIST + orphanRemoval = true [message #842160 is a reply to message #840030] Thu, 12 April 2012 03:33 Go to previous message
kyle shanahan is currently offline kyle shanahanFriend
Messages: 2
Registered: April 2012
Junior Member
thank you for the reply.

the "NE3_ID" field has no other mappings.
i'll try verbose logging.

thanks.
Previous Topic:Nested cascade
Next Topic:PK Violation on Many-to-One Child Record
Goto Forum:
  


Current Time: Sat Apr 20 02:59:39 GMT 2024

Powered by FUDForum. Page generated in 0.03571 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top