[jboss-user] [EJB 3.0] - Re: Eager fetching missing an element when retrieved remotel
Bigdaddy
do-not-reply at jboss.com
Thu Jan 29 15:20:17 EST 2009
Wow, I almost forgot about this.
I still do not know what the problem is with this implementation of @ManyToMany. Actually, I do not believe anything is wrong with the code as written. I am fairly certain there is a problem with Hibernate, the entity manager, data marshaller, or something else. I would welcome someone to point out a mistake that I may have made.
Anyhow, for those interested there is a workaround. Create the relational entities (i.e. ParentChildTbl and ChildGrandchildTbl) yourself and apply @ManyToOne, @OneToMany annotations with Sets-- not Collections-- for the foreign attributes on the ChildTbl and eager fetching will work as expected. If you must use Collections, I read somewhere that setting the hibernate annotation @Fetch(FetchMode.SUBSELECT) on bags (Collections) may work or you may use a List with an @IndexColumn.
For example:
Under ChildTbl.java
(Similarly, update ParentTbl.java and GrandchildTbl.java. They would have @OneToMany relationships with ParentChildTbl.java and ChildGrandchildTbl.java, respectively)
| ...
| @Id
| @GeneratedValue(generator = "system-uuid")
| @Column(name = "child_id", nullable = false)
| private String childId;
|
| @Column(name = "notes")
| private String notes;
|
| @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "childTbl")
| private Set<ParentChildTbl> parentChildTblSet
|
| @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "childTbl")
| private Set<ChildGrandchildTbl> grandchildTblSet;
| ...
|
Create ChildGrandchildTbl.java (Similarly create ParentChildTbl.java)
| ...
| @EmbeddedId
| protected ChildGrandchildPK childGrandchildPK;
|
| @JoinColumn(name = "child_id", insertable = false, nullable = false, updatable = false)
| @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
| private ChildTbl childTbl;
|
| @JoinColumn(name = "grandchild_id", insertable = false, nullable = false, updatable = false)
| @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
| private GrandchildTbl grandchildTbl;
| ...
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4205671#4205671
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4205671
More information about the jboss-user
mailing list