This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Toplink not using datasource from applicationContext

Oct 2nd, 2008, 11:00 PM

I have the below applicationContext.

My problem is in glassfish using TopLink jpa, toplink is trying to use the default datasource instead of what I have specified in spring. I can tell this because the exception thrown is a sql exception thrown when toplink is trying to connect to the derby datapool instead of my datasource.

I have added -javaagent:${com.sun.aas.instanceRoot}/lib/spring-agent.jar to my vm config and the log looks like it is loaded.

Any ideas as to why the entitymanager is using the default connection instead of what I specify in spring?

I am guessing maybe the the app servers entitymanager is being injected instead of the spring defined one. Though I have followed the many examples around and I think this should not be the case.

Does spring just create another entitymanager or does it use/modify the app servers?

I have atteched my applicationContext.xml and persistence.xml in the one file.

Comment

I have the same problem trying to run the Petclinic sample after setting up a workspace inside of Jdeveloper 10.1.3.4 and using the applicationContext-jpa.xml setup.

The persistence.xml in that example has no mention of a datasource. It's all in the applicationContext file. BUT, it still doesn't connect to the database. It appears to be attempting to connect to an OracleDS datasource. This must be defined inside of glassfish/toplink as some sort of default, in combination with how the persistence.xml is loaded.

The only workarounds that I have so far are:
1. Define a jdbc/oracleDS datasource
2. or rename persistence.xml to persistence-xxx.xml and then point the applicationContext-jpa.xml to that file. In that case, I have to define a persistenceUnitManager inside of the context file as well and pass reference that from the EntityManager bean.