Hi everybody,
I have the following issue: all tables in my database have the technical fields like createDate, idCreateUser, changeDate, idChangeUser. These fields are managed by triggers (no way to change it). I have the following parent in all entities from this reason:
Code:
@MappedSuperclass
public abstract class AbstractEntity {
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATE_DATE", updatable = false, insertable = false)
@Generated(GenerationTime.INSERT)
private Date createDate;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_CREATE_USER", updatable = false, insertable = false)
@Generated(GenerationTime.INSERT)
private UserEntity createUser;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CHANGE_DATE", insertable = false, updatable = false)
@Generated(GenerationTime.ALWAYS)
private Date changeDate;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_CHANGE_USER", updatable = false, insertable = false)
@Generated(GenerationTime.ALWAYS)
private UserEntity changeUser;
...
}
I've had no troubles with this structure till migration from Hibernate 3.6.1 to Hibernate 4.3.6. It seems that mapping (@JoinColumn) doesn't work for generated values anymore (although it did). The application throws the common exception
Code:
org.hibernate.MappingException: Unknown entity:...
As I did some debugging the Hibernate tries to initialize the first entity (I don't know in which order it loads the entities - I use Hibernate with Spring and use the packagesToScan feature) and it fails at creating of its own representation because the UserEntity is not known to him.
Does anybody have the similar experience or ideas what to do here?
Thank you in advance!