aspose file tools*
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 Java 8 in Action this week in the Java 8 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
Author

toplink.jdbc.url ignored in persistence.xml

Jim Petersson
Ranch Hand

Joined: May 28, 2008
Posts: 48
Hi,
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: 10.4.2.0 - (689064)
Driver: Apache Derby Network Client JDBC Driver Version: 10.2.2.1 - (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?

Thanks
[ 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: http://aspose.com/file-tools
 
subject: toplink.jdbc.url ignored in persistence.xml
 
Similar Threads
no error but entity is not persisted
Hibernate: Error getting property 'lastItem'
Exception while deploying the bean
JPA - problem with persistence.xml
Problem javax.persistence.NoResultException: No entity found for query