No persistence manager found: lazy initialization ignored for Account

29 views
Skip to first unread message

Oliver Günther

unread,
Apr 22, 2014, 7:35:15 AM4/22/14
to gran...@googlegroups.com
Hi,

I'm playing around with the addressbook tutorial.
After some rewrite and reconfiguration, I got it alive.

Server: Tomee 1.6.0.1 with Hibernate
Java: 1.7.0_u55-x64
Debian 7 / amd64

Now I wanted to see the magic of remote lazy loading. And here I'm stuck.
The client fails with NullPointerException and the Server gives a No persistence manager found: lazy initialization ignored for Account...

I've added the sample. To reproduce:
- mvn clean install the hole project tree.
- in server-ejb: tomee:run
- in client-tryout: jfx:run

Any Ideas ?

It would also be nice to have some documentation about the discovery of the EntityManager in LazyLoading. All I know is, that GraniteDs does it by itself and I cannot configure anything in an EJB environment.

Thanx,
Olli
sample.zip

Oliver Günther

unread,
Apr 25, 2014, 9:28:41 AM4/25/14
to gran...@googlegroups.com
Anyone ?
No Idea ?

wdrai

unread,
Apr 25, 2014, 11:59:11 AM4/25/14
to gran...@googlegroups.com
You can set the entityManagerJndiName or entityManagerFactoryJndiName in the @ServerFilter annotation (note: it's definitely missing in the docs...)
It's not sure that Tomee puts the EMF in a global JNDI by default, thus it may be also necessary to add a persistence-context-ref in web.xml.

Next your example will not work as is. Collection loading is an asynchronous operation and you have to use a callback to iterate over the elements:
for (Account account : futurResult.get().getResultList()) {
            Iterator<Box> iterator = account.getBoxes().iterator(); => does not work
}

for (Account account : futurResult.get().getResultList()) {
            ((PersistentCollection)account.getBoxes()).withInitialized(new InitializationCallback() {
                public void call(PersistentCollection boxes) {
                     Iterator<Box> iterator = boxes.iterator();
                }
            });
}
or in Java 8:
for (Account account : futurResult.get().getResultList()) {
            ((PersistentCollection)account.getBoxes()).withInitialized(boxes -> { Iterator<Box> iterator = boxes.iterator(); ... });
}

Oliver Günther

unread,
Apr 27, 2014, 4:35:51 PM4/27/14
to gran...@googlegroups.com
Hi,

thanx for the hint.
For now this is a show stopper, because Tomee doesn't seam to bind EntityManagers in the JNDI Tree. Looking into that.
But still, I have two questions:

1. Am I right to assume, that this allows only one Datasource for the hole application ?

2. I don't really get the withInitialized part you show. In documentation is written, that these are only needed if I want to manipulate the lazy loaded values. Also, if what u write is correct, wouldn't it contradict the transparent loading of entities. If I need to implement some callback for every collection I could do it without graniteds, with nearly the same effort.

Regards,
Olli
Reply all
Reply to author
Forward
0 new messages