Hey all,
I am working with a project which has always used hbm.xml files to specify its hibernate mappings. Trying to be proactive and moving the company to a better standard I am attempting to create a new @Entity using annotations. What I am finding though is when the LocalSessionFactoryBuilder is running through the configuration we have set up. It will scan the old mappings of HBM files we have then attempt to read in the one @Entity by its classpath. When it tries to pick up the class it is getting tripped up when trying to make a @ManyToOne connection to an old HBM defined entity and throws an error.
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com...NewEntity references an unknown entity: com...OldEntity
I have tried tweaking every config that I could this would be the problem and am at a loss. Everything seems to be picked up properly, it is just not letting the newer entity access the rest of the context. If I go to the older entity and add in a @Entity tag to it, it will then instead throw a “Duplicate entity” error rather than the unknown entity one.
Here is the new entity I am trying to create
@Entity
public class NewEntity {
private Long id;
private OldEntity oldEntity;
private DateTime createdDate;
@Id
@GeneratedValue
@Column(name = "id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@ManyToOne(targetEntity = OldEntity.class)
@JoinColumn(name = "oldEntity")
public OldEntity getOld() {
return oldEntity;
}
public void setOldEntity(OldEntity oldEntity) {
this.oldEntity = oldEntity;
}
@Column
public DateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(DateTime createdDate) {
this.createdDate = createdDate;
}
}