[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] @PrePersist failing on InheritanceType.TABLE_PER_CLASS
|
At least I believe that is what is happening. I am using EclipseLink 2.3.2 where I have an entity that has a one-to-many with a concrete child entity and an inheritance structure on another child entity using TABLE_PER_CLASS inheritance. I have a class that marks all entities with a createDate using JPA @PrePersist. On the concrete entity this works fine, however it does not update the entity being created that is using inheritance. I get a MySQLIntegrityConstraintViolation as the create_date column is required but not being created on the inherited class prior to persist. I've seen a few rumblings similar to this elsewhere but nothing directly regarding @PrePersist. Any help greatly appreciated.
Things look like this:
public class ManagedEntityListener {
@PrePersist
public void prePersist(Object entity) {
final CSPContext context = CSPContextHolder.getContext();
((ManagedPlatformEntity) entity).setCreateTime(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime());
}
}
}
// All classes inherit from this mapped superclass for createDate property
@MappedSuperclass
public abstract class ManagedEntity() {
@Column(name = "csp_create_dtt", nullable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
protected Date createTime;
...
}
// Parent class
public class ParentClass() {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
....
// Concrete Child
@OneToMany(cascade = CascadeType.PERSIST,
fetch = FetchType.LAZY,
targetEntity = ChildClass.class)
@JoinColumn(name = "parent_class_id")
private List<ChildClass> addressList = new ArrayList<ChildClass>();
// Inheritance Child
@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumn(name = "parent_class_id")
private List<InheritanceChild> inheritanceChild;
...
}
// Concrete ChildClass
@Entity
@Table(name = "child_class")
public class ChildClass() extends ManagedEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "fieldA")
private String fieldA;
@Column(name = "fieldB")
private String fieldB;
@Column(name = "fieldC")
private String fieldC;
@Column(name = "csp_create_dtt", nullable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
...
}
// InheritanceChild base class
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class InheritanceChild extends ManagedEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
private Account account;
// getters and setters for Account and Id
...
}
// ConcreteInheritedChild
@Entity()
@Table(name = "inherited_child_a")
public class InheritedChildA extends InheritanceChild {
@Column(name = "some_field")
private String someField;
}
Again in this structure, ChildClass is populated with createDate but InheritedChildA does NOT populate the createDate and throws a constraint violation from MySQL. Thanks in advance for any insight on this.
Mike Key