Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring data source - tomee.xml, persistence.xml

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?

like image 317
Vladimir Avatar asked Dec 09 '25 23:12

Vladimir


2 Answers

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.

like image 191
Alfredo Osorio Avatar answered Dec 12 '25 14:12

Alfredo Osorio


It might be a bit late to answer this, You can in tomee place the resource definition in WEB-INF/resources.xml.

like image 45
Ron Avatar answered Dec 12 '25 13:12

Ron