Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink persistance.xml Tomcat OSGI
EclipseLink persistance.xml Tomcat OSGI [message #494427] Fri, 30 October 2009 15:16 Go to next message
Ashish  is currently offline Ashish Friend
Messages: 13
Registered: September 2009
Junior Member
Hello,
I am working on project which uses EclipseLink and OSGi on Tomcat server. If I put persistence.xml in EclipseLink bundle (META-INF\persistence.xml) and deploy it in tomcat with bridge.war, it works very fine.

But I want to take out persistence.xml out of bundle jar and put that somewhere in Tomcat environment so that DB can be configured without changing the bundle jar.

My question is: Can I put META-INF\persistence.xml in tomcat environment where EclipseLink bundle is in bridge\WEB-INF\eclipse\plugin? If yes, please suggest me, where should I put it.

Thank you very much in advance.

Ashish
Re: EclipseLink persistance.xml Tomcat OSGI [message #494828 is a reply to message #494427] Mon, 02 November 2009 20:03 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
Hi Ashish,

I don't have any direct experience with your configuration but typically when deploying in a fully Java EE app server a datasource is used to decouple the persistence unit from the actual database. This is similar to your situation and may be the way to go.

Unfortunately, the OSGi Alliance specifications for JDBC and JNDI have not yet been finalized so until that is available you'll need some custom code.

I've blogged about how to pass a datasource to EclipseLink. So you can definitely remove the connection details from the persistence.xml but you have to find a way to instantiate the datasource and pass it into your EntityManagerFactory creation. I'm not sure where in Tomcat you could place the connection information and further you'd need to introduce an import-package for the driver itself. You could work around the import-package by obtaining the driver from a service (which is what the OSGi JDBC spec is going to do) or through some sort of wrapper bundle that decouples you from the actual driver class.

I think I raise more questions than I answer Wink, but hopefully some of the ideas I'm throwing out will get you started. The key question for you is even if you can extract the database connection information from the persistence.xml, how will EclipseLink or your code have visibility of the required JDBC driver?

--Shaun
Re: EclipseLink persistance.xml Tomcat OSGI [message #496619 is a reply to message #494427] Tue, 10 November 2009 16:59 Go to previous message
Thomas Haskes is currently offline Thomas HaskesFriend
Messages: 147
Registered: July 2009
Senior Member
Hi Ashish,

maybe it is a solution for you you not to use the persistence.xml at
all, as it can be overriden by the use of properties when creating the
emf. This would enable you to retreive the properties form outside the
bundle and put them into the emf. That way you could provide the
settings in a file outside the bundle jar. Im thinking of something like
this:

// retrive the the properties-file from somwhere and load it
.....

// hand it over to the emf, which will override the settings in the
persistence.xml

Properties props = loadFromExternalFile();

Persistence.createEntityManagerFactory("yourpu", props);

I think most of the configs can be overriden using the
PersistenceUnitProperties:

Example:

props.put("PersistenceUnitProperties.JDBC_USER", "User");


.... and so on.

HTH

Tom




Ashish schrieb:
> Hello,
> I am working on project which uses EclipseLink and OSGi on Tomcat
> server. If I put persistence.xml in EclipseLink bundle
> (META-INF\persistence.xml) and deploy it in tomcat with bridge.war, it
> works very fine.
>
> But I want to take out persistence.xml out of bundle jar and put that
> somewhere in Tomcat environment so that DB can be configured without
> changing the bundle jar.
>
> My question is: Can I put META-INF\persistence.xml in tomcat environment
> where EclipseLink bundle is in bridge\WEB-INF\eclipse\plugin? If yes,
> please suggest me, where should I put it.
>
> Thank you very much in advance.
>
> Ashish
Previous Topic:Connections from Connection Pool closed by database -> EL hangs
Next Topic:case insensitive "order by"
Goto Forum:
  


Current Time: Tue Mar 19 09:59:57 GMT 2024

Powered by FUDForum. Page generated in 0.01947 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top