Saturday, February 19, 2011

Enable JPA2 in Weblogic 10.3.4

WebLogic Server 10.3.4 Released - Key APIs of Java EE 6 and More
http://blogs.oracle.com/WebLogicServer/2011/01/weblogic_server_1034_released.html

Running JPA 2.0 API on WebLogic 10.3
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic#20110115:_JPA_2.0_using_EclipseLink_on_WebLogic_10.3.4.0

Enable JPA2 by adding JPA2 jar on PRE_CLASSPATH
http://download.oracle.com/docs/cd/E17904_01/web.1111/e13720/using_toplink.htm#CIHDJHHI

# Set up BEA Home
BEA_HOME="/usr/app"

PRE_CLASSPATH=$BEA_HOME/modules/javax.persistence_1.0.0.0_2-0-0.jar:$BEA_HOME/modules/com.oracle.jpa2support_1.0.0.0_2-0.jar



Create JPA2 project in Eclipse Helios 3.6
Update Server Runtime to WLS 10.3.4


Create WLS 10.3.4 domain


Edit EJB project facets


Edit JPA facet


Create JPA entities from tables


Generated JPA class
package dave;

import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
import java.math.BigDecimal;


/**
* The persistent class for the BOOKS database table.
*
*/
@Entity
@Table(name="BOOKS")
public class Book implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@SequenceGenerator(name="BOOKS_ID_GENERATOR", sequenceName="ID_GEN")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="BOOKS_ID_GENERATOR")
private long id;

private String author;

private BigDecimal counter;

@Column(name="INSERT_TIMESTAMP")
private Timestamp insertTimestamp;

private String title;

public Book() {
}

public long getId() {
return this.id;
}

public void setId(long id) {
this.id = id;
}

public String getAuthor() {
return this.author;
}

public void setAuthor(String author) {
this.author = author;
}

public BigDecimal getCounter() {
return this.counter;
}

public void setCounter(BigDecimal counter) {
this.counter = counter;
}

public Timestamp getInsertTimestamp() {
return this.insertTimestamp;
}

public void setInsertTimestamp(Timestamp insertTimestamp) {
this.insertTimestamp = insertTimestamp;
}

public String getTitle() {
return this.title;
}

public void setTitle(String title) {
this.title = title;
}

}


Edit persistence.xml
<persistence version="2.0" 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">
<persistence-unit name="example" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/XE</jta-data-source>
<class>dave.Book</class>
<shared-cache-mode>NONE</shared-cache-mode><!-- shared-cache-mode must come after any class definitions (usually SE only) - the JPA schema is ordered -->
<properties>
<property name="eclipselink.target-server" value="WebLogic_10"/>
<property name="eclipselink.target-database" value="Oracle"/>
<property name="eclipselink.logging.level" value="FINEST"/>
<!-- new for 10.3.4.0 http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging#Server_Logging -->
<property name="eclipselink.logging.logger" value="DefaultLogger"/>
<!-- turn off DDL generation after the model is stable -->
<!-- property name="eclipselink.ddl-generation" value="drop-and-create-tables"/-->
<!-- property name="eclipselink.ddl-generation.output-mode" value="database"/-->
</properties>
</persistence-unit>
</persistence>

1 comment:

  1. Even in the older weblogic versions 10.3.x there are ways to configure your JPA2.0 application using ORMS other then EclipseLink and the way suggested in my blog below doesn't even need to install any patch or add any new libraries in server class path, Please have a look

    http://javaiscoool.blogspot.com/2012/12/deploy-jpa20-application-on-weblogic1033.html

    ReplyDelete