I'm currently attempting to map these 2 entities in a bi-directional relationship but getting an exception as shown. The entities
Book.java:
@Entity
@Table(name = "Book")
public class Book {
@Id
@GeneratedValue
@Column(name = "id")
private Long id;
@OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="bookId")
private Collection<Author> authors;
public Collection<Author> getAuthors() {
return authors;
}
...
}
Author.java:
@Entity
public class Author {
@Id
@GeneratedValue
@Column(name="id")
private Long id;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="author_id")
private Long bookId;
...
}
The exception:
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: BookStore] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at org.hibstore.dao.DAOTest.main(DAOTest.java:10)
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on org.hibstore.domain.Author.bookId references an unknown entity: java.lang.Long
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:109)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1514)
Any ideas?