This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes toplink.jdbc.url ignored in persistence.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "toplink.jdbc.url ignored in persistence.xml" Watch "toplink.jdbc.url ignored in persistence.xml" New topic

toplink.jdbc.url ignored in persistence.xml

Jim Petersson
Ranch Hand

Joined: May 28, 2008
Posts: 48
I'm trying to set up a JPA-project ith Glassfish and Derby.
I have one problem, the database "sun-appserv-samples" is used all the time, even though I try to set a different value in my persistence.xml

This is printed to the log:
Connected: jdbc erby://localhost:1527/sun-appserv-samples;;create=true
User: user
Database: Apache Derby Version: - (689064)
Driver: Apache Derby Network Client JDBC Driver Version: - (538595)|#]

My persistence.xml looks like this:

As you can see I'm trying to set the db to 'MyDB'. The values for user and password are used though. Any ideas what I'm doing wrong?

[ December 01, 2008: Message edited by: Jim Petersson ]

SCJP 5<br />SCJD
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
The way you have configured JPA and used it in Glassfish, the optional transaction-type attribute of persistence-unit element is set to JTA (default value when used in a container). If you want to provide the URL as a property in persistence.xml, you should change the transaction-type to RESOURCE_LOCAL. They way it is now, to make it work, you need to create additional connection pool and jdbc resource with the correct URL, or change the default derby pool to point to the database you need it to. If you create a new pool, you also need to specify a jta-data-source element on persistence.xml with the name of you newly configured pool. If you edit the default derby pool, you don't have to do that.
Some properties are taken into account by TopLink even when JTa is used, as logging and db-schema generation. I suppose the reason your user ans password are picked up is because the glassfish team would like you to be able to specify a new pass and user, and override the server defaults, even if you use the default data source.
Hope this helps, it did the trick for me (changing derby to oracle xe, I created a new pool of course).
Jim Petersson
Ranch Hand

Joined: May 28, 2008
Posts: 48
Ok that makes sense.
I know that you can configure a new datasource using the Glassfish admin console, but I want to be able to deploy my app on a different computer/glassfish server. How can I make it so that my datasource configuration is included with the EAR file?
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
I would say you can't contain the data source definition within you EAR file. When you deploy, you first create all server object that your application depends on, in this case - the data source.
One thing you could do is to create an ant build file, that creates all the necessary objects using asant, and then in the end call asadmin deploy, also in the ant build file. The deploy target could depend on the creation targets, so that when sth fails, the app wouldn't be deployed.
I agree. Here's the link:
subject: toplink.jdbc.url ignored in persistence.xml
Similar Threads
Hibernate: Error getting property 'lastItem'
Problem javax.persistence.NoResultException: No entity found for query
JPA - problem with persistence.xml
no error but entity is not persisted
Exception while deploying the bean