Reputation: 1694
I'm doing some EJB with JPA project that maps/persists some entities to mysql database. I have defined persistence unit in persistence.xml like this:
<persistence-unit name="MyAppPU" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>MyAppDS</jta-data-source>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
<property name="openjpa.jdbc.DBDictionary" value="mysql" />
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
</properties>
</persistence-unit>
Then, in tomee/conf/tomee.xml file i have defined data source like this:
<Resource id="MyAppDS" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql://127.0.0.1:3306/MyAppDB
UserName root
Password 123
JtaManaged true
DefaultAutoCommit false
</Resource>
All this works fine, i create MyApp.jar, deploy it to TomEE server, test it and i get mysql tables in database. My question is "Is there any other place where I could define data source resource?" Or it has to be in tomee/conf/tomee.xml file? Can it be defined somewhere inside application structure, in some xml file, and deployed inside apps jar file to server?
Upvotes: 3
Views: 9921
Reputation: 129
You only have to set the tomee.xml. If you are using Eclipse, you must copy the tomee.xml into the servers configuration/Tomee to get recognize it into the web project, otherwise you will get troubles.
Upvotes: 0
Reputation: 816
It might be a bit late to answer this, You can in tomee place the resource definition in WEB-INF/resources.xml
.
Upvotes: 3
Reputation: 11475
That's the whole point of a JNDI data source, to externalize it outside of your application, so you can modify it without recompiling or repackaging. So it is better to leave it this way.
For testing purpose, some EE server such as JBoss (Wildfly) let you define this in your project.
Upvotes: 3