| Problem with @Inheritance - Constraint violated [message #767912] | 
Mon, 19 December 2011 02:46   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Hi, 
 
I've a problem on a project with some inheritance in JPA with EclipseLink. I've following classes : 
 
1) Ref (is some references) 
@Entity
@Table(name = "REF")
public class Ref {
	// Some fields...
} 
 
2) AbstractObject is one abstract object, with several implementation (so is an abstract class, which is specified in other classes) 
@Entity
@Table(name = "ABSTRACT_OBJECT")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "TYPE_OBJECT")
public abstract class AbstractObject {
	@Id
	private Long id;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "FK_REF")
	private Ref ref;
	@Column(name = "TYPE_OBJECT")
	private String typeObject
} 
 
3) ObjectOne is one of this implementation, there may be other objects... 
@Entity
@Table(name = "OBJECT_ONE")
@DiscriminatorValue("ONE")
public class ObjectOne extends AbstractObject {
	// Some fields...
} 
 
4) Child is a child of ObjectOne (and only this) 
@Entity
@Table(name = "CHILED")
public class Child {
	@Id
	private Long id;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn("FK_OBJECT_ONE")
	private ObjectOne objectOne;
	// Some fields...
} 
 
I've allready one Ref instance in the database, and I'm saving (persist) the two following instances : 
 
 
-  ObjectOne
 
 -  Child
 
 
  
 
The object AbstractObject is automatically saved, when ObjectOne is persisted. 
 
In my logs, the Objects are saved in this order : 
 
 
-  AbstractObject
 
 -  Child
 
 -  ObjectOne
 
 
  
 
--> Result, my Constraint on child (foreign key to ObjectOne) is violated !! 
 
Why the Child is persisted before the ObjectOne ? I've assume that the AbstractObject and ObjectOne are atomicaly saved, but it isn't so. 
 
What can I change to correct this ? 
 
Im moment, I've a workarround : my Foreign Key is done between Child and AbstractObject, but it's not fine. 
 
 
Thanks for your help ! 
 |  
 |  
  | 
 | 
 | 
 | 
 | 
Powered by 
FUDForum. Page generated in 0.06257 seconds