Bug 402865 - Incorrect Cascade Discovery of new objects mapped from Embeddables
Summary: Incorrect Cascade Discovery of new objects mapped from Embeddables
Status: REOPENED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 critical with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: submitted_patch
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2013-03-11 03:35 EDT by J LM CLA
Modified: 2022-06-09 10:09 EDT (History)
1 user (show)

See Also:


Attachments
Patch on AggregateObjectMapping for cascadeDiscovery methods (2.51 KB, application/octet-stream)
2013-03-11 03:35 EDT, J LM CLA
no flags Details
Patch on AggregateObjectMapping for cascadeDiscovery methods by cascading the objectReferenced. (2.43 KB, application/octet-stream)
2013-03-25 05:51 EDT, J LM CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description J LM CLA 2013-03-11 03:35:21 EDT
Created attachment 228177 [details]
Patch on AggregateObjectMapping for cascadeDiscovery methods

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.

Proposed patch in attachment, compatible with 2.3.X and 2.4.X
Comment 1 J LM CLA 2013-03-25 05:51:52 EDT
Created attachment 228985 [details]
Patch on AggregateObjectMapping for cascadeDiscovery methods by cascading the objectReferenced.
Comment 2 J LM CLA 2013-03-25 05:53:46 EDT
The attached Patch resolves the issue.
Comment 3 J LM CLA 2013-06-26 01:31:48 EDT
Patch still needed.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:09:25 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink