I'm working with Seam 1.1, and building a new application. This application has an
Account object which is an Entity POJO. The account has many Sites, a Site has many
Flows, and a Flow has many Actions. All Entity POJOs. All One to Many relationships are
defined using Lists, as that is what makes sense.
Upon login, a User object gets loaded, there is a Many to One relationship between Users
and Accounts.
This is the getFlows method on the Site object, as an example, all the relationships are
similar:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy =
"site")
| @OrderBy("id")
| public List<Flow> getFlows() {
| return this.mFlows;
| }
My Login action uses an EntityManager provided by Seam:
@In(create = true)
| private EntityManager entityManager;
and in my persistance.xml I have:
<property name="jboss.entity.manager.factory.jndi.name"
value="java:/keynoteEntityManagerFactory" />
and in my components.xml I have:
<component name="entityManager"
| class="org.jboss.seam.core.ManagedPersistenceContext">
| <property name="persistenceUnitJndiName">
| java:/keynoteEntityManagerFactory
| </property>
| </component>
My problems are this:
If I try to use lazy loading, I can get the account from the user, and I can get the Sites
from the Account, but when I try to get the Flows from the Site I get these errors:
01:41:55,247 ERROR [LazyInitializationException] failed to lazily initialize a collection
of role: com.digitalsanctuary.keynote.ejb.Site.flows, no session or session was closed
| org.hibernate.LazyInitializationException: failed to lazily initialize a collection of
role: com.digitalsanctuary.keynote.ejb.Site.flows, no session or session was closed
If I try to use Eager loading I get:
cannot simultaneously fetch multiple bags
Errors. If I try to use the @IndexColumn annotation as per the threads on this error in
Hibernate forums, then I get empty items in my list until the actual index id shows up
(i.e. The list of Sites for a given account may have primary key id's of 5, 6, 7, and
8. When I use the IndexColumn annotation, my List of Sites ends up with 5 empty items
before the 4 real items (this not only causes code issues, but makes my data tables look
awful).
Basically I can't figure out the right combination of settings to get things to work.
Ideally I'd like to Lazily load everything, as many user flows won't require the
sub-items, however, I can't figure out how to avoid the LIE, even though I'm using
the Seam EntityManager.
I'm new to EJB3, and pretty new to Seam, but I've been pouring over the docs and
forums and so far haven't worked it out. Any help would be greatly appreciated.
Thanks!
Modoc
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3997195#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...