• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Spring + JPA/Hibernate + Persistence.xml + applicationContext.xml + ANT hbm2ddl

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How's that for a subject. So I am working on a new project where we are using JPA/Hibernate and Spring for transactional service junk and using JpaDaoSupport.

I want to completely decouple the database generation from the server startup process so I am using the Ant hibernatetool task like so:


I have a Data Source defined in Spring using c3p0 but because the Ant task doesn't know about Spring I also have redundant info in the persistence.xml file. Is there a way to

a) tell the ant task to use a spring defined database (probably not would be my guess)

b) tell Spring to use the data source defined in the persistence.xml file

If the answer is possible with (b) then I have another question...

b.1) Is there a way to tell the persistence.xml file to use a properties file with the connection info rather than putting it directly in the xml file and if so (yes, another question) can you pull in an environment variable to use for the path?

For example, right now I am doing this in the applicationContext.xml file like so:



where environment is an environment variable set when the server starts.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Gregg Bolinger:
b.1) Is there a way to tell the persistence.xml file to use a properties file with the connection info rather than putting it directly in the xml file



Don't know the answers to other questions (haven't used Spring), but for this one you need not specify the connection properties in the persistence.xml. Instead you could point the persistence.xml to a datasource bound to JNDI:





The creation of the datasource and binding it to JNDI itself would be a separate task (which i think you are already doing through your Spring configuration files).

Update: I just re-read the question. My answer probably doesn't make any sense if you are going for option b, since you are trying to define the datasource through the persistence.xml
[ October 26, 2008: Message edited by: Jaikiran Pai ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, thanks. I'm not defining the data source via jndi so it doesn't help too much. I'd like to keep the definition in one place though so maybe I need to look into that option. The question still remains though, if I were to define the data source in the persistence.xml (via jndi or whatever) how does Spring know to use that as well without redundant info in both files?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

just struggling with about the same issue. Could you find a solution? My problem is I want to switch Dialects for DDL generation so an extern properties file would be great.

Best regards

Frank
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So tonight I spent some time figuring this out. Turns out you can specify a propertyfile containing database connection info to jpaconfiguration. So it looks something like this:

 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!