Made some changes to see what I could do here.
In the BookCatAccess class, I changed to use @IdClass. Got a little farther than before.
@Entity
@Table(name="BOOKCAT_ACCESS")
@IdClass(BookCatAccess.BookCatAccessId.class)
public class BookCatAccess {
@Id
private String bookCategory;
@Id
private Long accessLevel;
...
@Embeddable
public class BookCatAccessId implements Serializable {
@Column(name="BCCA_BOOK_CATEGORY")
private String bookCategory;
@Column(name="BCCA_ACCESS_LVL")
private Long accessLevel;
}
My titles class now has the following for it's mapping (I removed the referenced name):
@OneToMany()
@JoinColumn(name="BCCA_BOOK_CATEGORY")
private List<BookCatAccess> bookCategoryAccessList;
Interestingly, now I have a query coming back properly; however, it using the value of the primary key on the Titles entity rather than the join column I have specified. In other words, it should bind to 'V' rather than '3434610'.
select bookcatego0_.BCCA_BOOK_CATEGORY as BCCA2_1_,
bookcatego0_.BCCA_ACCESS_LVL as BCCA1_1_,
bookcatego0_.BCCA_ACCESS_LVL as BCCA1_11_0_,
bookcatego0_.BCCA_BOOK_CATEGORY as BCCA2_11_0_,
bookcatego0_.BCCA_QTY_LIMIT as BCCA3_11_0_,
bookcatego0_.BCCA_SHOW_PRICE_FLAG as BCCA4_11_0_
from BOOKCAT_ACCESS bookcatego0_
where bookcatego0_.BCCA_BOOK_CATEGORY='3434610'
So, next I changed the @JoinColumn above my Titles list to the following:
@JoinColumn(name="BCCA_BOOK_CATEGORY", referencedColumnName="TITL_BOOK_CAT")
Now, I am getting a new error. Its a ClassCastException:
[junit] Error: com.fb.model.Titles
[junit] java.lang.ClassCastException: com.fb.model.Titles
[junit] at org.hibernate.type.CollectionType.getKeyOfOwner(CollectionType.java:348)
[junit] at org.hibernate.type.CollectionType.resolve(CollectionType.java:368)
[junit] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
[junit] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
[junit] at org.hibernate.loader.Loader.doQuery(Loader.java:729)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
[junit] at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
[junit] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
[junit] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
[junit] at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98)
[junit] at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
[junit] at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836)
[junit] at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66)
[junit] at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
[junit] at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
[junit] at com.fb.model.Titles$$EnhancerByCGLIB$$602e545c.getTitleCatalogNumber(<generated>)
|