Incorrect Cascade Discovery of new objects mapped from managed Embeddables [message #1017751] |
Tue, 12 March 2013 13:32 |
J LM Messages: 11 Registered: December 2012 |
Junior Member |
|
|
Hi,
Simple use case :
TcRoot (Entity) -> TcEmbeddable (Embeddable) -> TcSubEntity (Entity)
@Entity
@Table(name = "TCEMB_ROOT")
@SequenceGenerator(name = "SEQ_TCEMB_ROOT")
public class TcRoot implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "SEQ_TCEMB_ROOT")
@Column(name = "TCEMB_ROOT_ID")
private int id;
@Embedded
TcEmbeddable emb;
public void changeSub(final String newAttr) {
emb.changeSub(newAttr);
}
}
@Embeddable
public class TcEmbeddable implements Serializable {
@OneToOne
@JoinColumn(name = "SUBE_ID", referencedColumnName = "TCEMB_SUBE_ID")
TcSubEntity tcSE;
public void changeSub(final String newAttr) {
tcSE = new TcSubEntity(newAttr);
}
}
@Entity
@Table(name = "TCEMB_SUBE")
@SequenceGenerator(name = "SEQ_TCEMB_SUBE", sequenceName = "SEQ_TCEMB_SUBE")
public class TcSubEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "SEQ_TCEMB_SUBE")
@Column(name = "TCEMB_SUBE_ID")
private int id;
}
After a find of a TcRoot (so managed) and a call on its method changeSub, a new SubEntity is created, transaction fails with Constraint Violation as the Id of the TcSubEntity is not set or take the 0 value.
Having looked at the code, the AggregateObjectMapping seems incomplete on the methods cascadeDiscoverAndPersistUnregisteredNewObjects.
One is inherited from DatabaseMapping which returns always false, the second one doesn't seem to be called.
Bug and Proposed patch for 2.3.X and 2.4.X : https://bugs.eclipse.org/bugs/show_bug.cgi?id=402865
[Updated on: Tue, 12 March 2013 13:34] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02609 seconds