0

We need to replace the user defined properties of database details with the JTA tag using Eclipse Link. I have the below persistence.xml working with DB values.

<?xml version="1.0" encoding="UTF-8"?>
<persistence xsi:SchemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit transaction-type="RESOURCE_LOCAL" name="UTILITY">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>ae.du.selfcare.utility.jpa.SelfcareJmsCreatett</class>
<properties>
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:Oracle:thin:@IMP1SCDVDB1:1524:SCRTQC2"/>
<property name="javax.persistence.jdbc.user" value="******"/>
<property name="javax.persistence.jdbc.password" value="********"/>
<property name="eclipselink.connection-pool.default.initial" value="1"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
</properties>
</persistence-unit>
</persistence>

I know how to achieve using this JTA with Hibernate

 <persistence-unit name="PU" transaction-type="JTA">
        <jta-data-source>java:jboss/datasources/Hanse</jta-data-source>
        <class>model.Commodity</class>
        <class>model....</class>
        <class>model....</class>
        <properties>
            <!-- <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/> -->
            <!-- <property name="hibernate.hbm2ddl.auto" value="update" /> -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
            <!-- <property name="hibernate.show_sql" value="true" /> -->
            <property name="hibernate.enable_lazy_load_no_trans" value="true"/>
        </properties>
    </persistence-unit>

But here, I need to with Eclipse link. Can you please help me out. Thanks in advance!!.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1111880
  • 443
  • 5
  • 8
  • 26

3 Answers3

1

As you are using weblogic server you can use datasource. I am using 12c and I have the below persistance.xml, this may help you.

<?xml version="1.0" encoding="windows-1252" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
         version="2.0">
<persistence-unit name="WebService" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/MyDataSource</jta-data-source>
<class>model.HrAddressL1L2DataV</class>
<class>model.HrJobsLookupV</class>
<properties>
  <property name="eclipselink.target-server" value="WebLogic_10"/>
  <property name="javax.persistence.jtaDataSource" 
 value="jdbc/MyDataSource"/>
</properties>
</persistence-unit>
</persistence>
Sudip
  • 92
  • 7
1

The official EclipseLink documentation provides an nice tutorial page for this scenario in a WebLogic 10.x application server.

Configuring and binding to a DataSource involves basically three configuration steps. These are:

  1. Provide a definition of the data-source in a *-jdbc.xml configuration file. (within the EAR)
  2. Provide a JDBC module configuration snippet to the WebLogic Application configuration in /META-INF/weblogic-application.xml of the EAR.
  3. Change the JPA persistence unit to use the application scoped data source, for instance: <jta-data-source>java:/app/jdbc/SimpleAppScopedDS</jta-data-source>. Next, set transaction-type="JTA" instead of "RESOURCE_LOCAL" (within an EJB)

For further details, please refer to configuration examples the aforementioned tutorial.

Hope it helps.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
0

I know how to achieve using this JTA with Hibernate [...] But here, I need to with Eclipse link.

Using JTA managed data sources is pretty standard and just changing the persistence provider class should be enough, no special properties should be required to make it work:

<persistence-unit name="PU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/MyDataSource</jta-data-source>
    ...
</persistence-unit>

Of course you need to be sure there is a DataSource configured and accessible through JNDI in your application server and use the very same name in <jta-data-source/> property.

Take a look to DataSource Objects and Connection Pools section of JEE tutorial for further details.

dic19
  • 17,821
  • 6
  • 40
  • 69