[2.3.8-Java] JavaJPA - Using eclipselink JNDI context not populated with datasource name

560 views
Skip to first unread message

Old Dave

unread,
May 13, 2015, 9:47:00 AM5/13/15
to play-fr...@googlegroups.com
Hi,

I switched my Eclipse Texo generated source across from Jetty to Play. But despite following the JavaJPA documentation to the letter I find the DataSource defined in my application.conf and conf/META-INF/persistence.xml is not set in the JNDI context, so if fails to find it. 


Exception Description: Cannot acquire data source [DefaultDS].
Internal Exception: javax.naming.NameNotFoundException: DefaultDS not found
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:520) ~[eclipselink-2.5.0.jar:2.5.0.v20130507-3faac2b]
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109) ~[eclipselink-2.5.0.jar:2.5.0.v20130507-3faac2b]


Here is the relevant part of my application.conf

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:file://C:/Users/olddave/git/pss/db/pss_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"
db.default.user="sa"
db.default.password="pss@1234"
db.default.jndiName=DefaultDS
#
# You can expose this datasource via JNDI if needed (Useful for JPA)
jpa.default=default


And my persistence.xml 

<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <non-jta-data-source>DefaultDS</non-jta-data-source>
<class>com.example.pss.AdvancedConfig</class>
...
<properties>
            <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform"/>
            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:h2:file://C:/Users/olddave/git/pss/db/pss_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"/>
          <property name="javax.persistence.jdbc.user" value="sa"/>
            <property name="javax.persistence.jdbc.password" value="********"/>
<property name="eclipselink.ddl-generation" value="none" />
<property name="eclipselink.ddl-generation.output-mode" value="both" />
</properties>
</persistence-unit>
</persistence>


and the relevant part of build.sbt


libraryDependencies ++= Seq(
  "org.eclipse.persistence" % "eclipselink" % "2.5.0",
  cache,
  javaWs,
  javaJpa
)


Any ideas?

Old Dave

unread,
May 14, 2015, 11:35:54 AM5/14/15
to play-fr...@googlegroups.com
Anyone?

I hate the idea I have to abandon Texo & EclipseLink and use EBean. Either I made some error, or JPA support is somehow broken/limited to Hibernate?

Matthias Kurz

unread,
May 14, 2015, 12:03:16 PM5/14/15
to play-fr...@googlegroups.com
From: http://stackoverflow.com/a/11648086/810109
Try:
<non-jta-data-source>java:/DefaultDS</non-jta-data-source>

Maybe that helps.
What version of Play are you using?

Regards,
Matthias

Old Dave

unread,
May 14, 2015, 12:23:02 PM5/14/15
to play-fr...@googlegroups.com
Hi,

2.3.8

Caused by: org.eclipse.persistence.exceptions.ValidationException: 
Exception Description: Cannot acquire data source [java:/DefaultDS].
Internal Exception: javax.naming.NameNotFoundException: DefaultDS not found

If you point me at the course code where the application.conf setting for the jndi name gets setup maybe I can find out why it is not?


Old Dave

unread,
May 14, 2015, 12:23:41 PM5/14/15
to play-fr...@googlegroups.com
Clearly I mean source code...

Matthias Kurz

unread,
May 14, 2015, 12:30:44 PM5/14/15
to play-fr...@googlegroups.com
This?

Did you read through the stackoverflow answer and also tried:
<non-jta-data-source>jdbc:/DefaultDS</non-jta-data-source>
?
(Also I think in the answer were some other things mentioned you could try)

Matthias Kurz

unread,
May 14, 2015, 12:32:32 PM5/14/15
to play-fr...@googlegroups.com
Does following line get logged?
datasource XXX bound to JNDI as XXX

Old Dave

unread,
May 15, 2015, 4:22:51 AM5/15/15
to play-fr...@googlegroups.com
Hi,

Yes, I read your answer and tried that. Nothing substantive was added by the link to the problem of configuring JPA in JBoss.

One thing that confused me a little is that the Plat application.conf includes these 
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:file://C:/Users/olddave/git/pss/db/pss_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"
While these same settings appear in persistance.xml as

            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:h2:file://C:/Users/olddave/git/pss/db/pss_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"/>

The exception I posted in response states the JNDI not found is "java:/DsDefault".

The application.log and the console have no trace of the message "datasource XXX bound to JNDI as XXX"

I'll install the Scala plugin in Eclipse and trace to the line you mentioned and get back to you.

Old Dave

unread,
May 15, 2015, 7:04:25 AM5/15/15
to play-fr...@googlegroups.com
Great, I try to add a breakpoint at the line 399 of the DB.scala and I get 

"A breakpoint cannot be set at the selected editor location" in the Eclipse status bar while in the Scala perspective. I added the source attachments after running "activator eclipse wit-source=true".

Goggle it, no help on that one. 

At a standstill. Maybe back to a Jetty Uberjar where the Texo JPA works. Sigh.

Mirco Dotta

unread,
May 15, 2015, 7:32:53 AM5/15/15
to play-fr...@googlegroups.com
Hi,

Could you check if the class you are trying to debug has the debug information?


— Mirco
----------------
Mirco Dotta - @mircodotta

Typesafe – Build reactive apps!

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Old Dave

unread,
May 15, 2015, 8:03:04 AM5/15/15
to play-fr...@googlegroups.com
Yes it does have debug information in the class file. Maybe it is a weakness in the Eclipse Scala Plugin itself?
But the fact is that I switched to Play because it is more integrated, with most of the services I need after having lots of issues with Jetty with lots of other libraries added to support JSON RESTful contracts, lots of metadata in J and run scheduled Akka workflows. When Play becomes just as complex to get working then it is time to move onto a solution that will not give me so many issues. If I rewrote all my metadata database code to use EBean then maybe I would get there. It is always a trade off ease of use if you use all the embedded services for a framework like Play, or more complexity but more control if you roll your own on top of a server like Jetty.

Old Dave

unread,
May 18, 2015, 7:11:47 AM5/18/15
to play-fr...@googlegroups.com
Hi,

One thing I noticed was that the hibernate-jpa-2.0-api-1.0.1.Final.jar was still under Referenced Libraries in my project. I had read a tutorial that it interferes with other JPA implementations ( Kundera in that case). Could this be the problem? I no longer have javaJdbc as a dependency in my build.sbt, wondering how to get rid of this jar in my list of referenced libraries?



On Friday, 15 May 2015 12:32:53 UTC+1, Mirco Dotta wrote:

Old Dave

unread,
May 18, 2015, 8:57:15 AM5/18/15
to play-fr...@googlegroups.com
I tried taking the JPA out of the hands of Play. I put the eclipselink and javax.persitence jars in lib for they end up on the classpath. The Texo generated *ModelPackage class will initialize the DataSource. But in the end no matter where I put the persistence.xml (base package, META-INF and conf/META-INF) it does not seem to find it. So abandon ship now. I had tried following this - https://pbaris.wordpress.com/2013/07/29/play-framework-2-jpa-eclipselink-setup/ but still get consistent exception - "Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named default"


On Friday, 15 May 2015 12:32:53 UTC+1, Mirco Dotta wrote:
Reply all
Reply to author
Forward
0 new messages