Java, Programming

Change Seam Persistence Provider From Hibernate To EclipseLink

change-seam-persistence-provider-from-hibernate-to-eclipselink

JBoss Seam default Persistence Provider is Hibernate. If you want to change the Persistence Provider from Hibernate to OpenJPA, here is a tutorial: http://seamframework.org/Documentation/UsingOpenJPAAsPersistenceProviderInsteadOfHibernate

OK, Here is a method to change the Persistence Provider to EclipseLink.
First. Edit the persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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_1_0.xsd"
    version="1.0">
    <persistence-unit name="opentutorial" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <non-jta-data-source>jdbc/oracle</non-jta-data-source>
        <class>com.opentutorial.entity.User</class>
        <class>com.opentutorial.entity.UserInfo</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="eclipselink.target-server" value="JBoss" />
            <property name="eclipselink.target-database" value="Oracle" />
            <property name="eclipselink.logging.level" value="INFO" />
            <property name="eclipselink.logging.timestamp" value="true" />
            <property name="eclipselink.logging.session" value="true" />
            <property name="eclipselink.logging.thread" value="false" />
            <property name="eclipselink.logging.exceptions" value="true" />
            <property name="eclipselink.cache.type.default" value="NONE" />
        </properties>
    </persistence-unit>
</persistence>

 

  • transaction-type must be RESOURCE_LOCAL
  • provider change to EclipseLink’s PersistenceProvider
  • Must be non-jta-data-source
  • Declare all entity class

Now, edit components.xml, add below tag value in components.xml:

<transaction:entity-transaction
    entity-manager="#{entityManager}" />
<persistence:entity-manager-factory
    persistence-unit-name="opentutorial" name="entityManagerFactory" startup="false" />

<persistence:managed-persistence-context
    name="entityManager" auto-create="true" entity-manager-factory="#{entityManagerFactory}" />

<component class="org.jboss.seam.persistence.PersistenceProvider"
    name="org.jboss.seam.persistence.persistenceProvider" scope="stateless" />

Now. The seam will use EclipseLink as your PersistenceProvider.

Tags: