Showing posts with label ejb. Show all posts
Showing posts with label ejb. Show all posts

Tuesday, May 10, 2016

WebLogic 10.3.x Error : NoSuchMethodError for javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode

As of now mostly trend is using newer frameworks or migrating from older framework to newer one.
One of the classic situation we started facing with Application Deployment once we have done migration.

Technology Stack we are using in our Applications is as below:
·         Java 7
·         JPA 2.0
·         Spring 3.0
·         Hibernate 3.0
·         EJB 3.0
·         Oracle 11g

While deploying we are getting below exception:
Caused By: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
at org.hibernate.ejb.util.LogHelper.logPersistenceUnitInfo(LogHelper.java:39)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:516)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at weblogic.deployment.PersistenceUnitInfoImpl.createEntityManagerFactory(PersistenceUnitInfoImpl.java:352)
at weblogic.deployment.PersistenceUnitInfoImpl.createEntityManagerFactory(PersistenceUnitInfoImpl.java:332)


In development environment we are using below for deployment:
·         WebLogic 12
·         Oracle 11g

So what is cause for this?
·         Pre-Production and Production environment having:
o   WebLogic 10.3.5
o   Oracle 11g

As database point of view there is no issue.
So it's mostly application server compatibility issue.
JPA Jars which WebLogic 10.3.5 is having are of different versions than application requires.

So as to resolve this issues, following are 2 possible solutions:
·         Application Level Changes:
o   Adding ANTLR specific changes to be done in weblogic-application.xml file located under META-INF.
<?xml version="1.0" encoding="UTF-8"?>


       <!--  This is needed since WL has a different version of antlr jar-->
    <prefer-application-packages>
        <package-name>antlr.*</package-name>
    </prefer-application-packages>
   
</weblogic-application>

o   Adding JPA specific JARs to application WAR/EAR only.
§  Hibernate-jpa-api.jar
§  Weblogic-fullclient.jar

·         WebLogic Level – Configuration changes:



--
III  Best Regards,
III  Abhijeet.

Wednesday, June 26, 2013

Using VIRTUAL Column in JPA Entity


While working with Java Persistence using ORM Layer, new feature from Oralce 11g can be useful.
E.g. Virtual Column.
 
Whenever want to use Virtual Column in JPA Entity, it should follow:
  • Field should not be Updatable.
  • Field should not be populated while creating the entity.

For such scenario, one has to use below annotation on field:
@Column(insertable=false, updatable=false)

Below is Detailed Example JPA Entity with Virtual Column usage:

Virtual Column Should be added like:
alter table cosnumers add(
     IS_ADMIN GENERATED ALWAYS AS ( CASE WHEN CONSUMER_ID IS NOT NULL THEN 1 ELSE 0 END)
);

JPA Entity Should define field for Virtual Column as shown below:
Package com.acp.jpa;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class Consumer {

       private Long consumerID;

       @Column(insertable=false, updatable=false)
       private boolean isAdmin;
      
       /**
       * @return the consumerID
       */
       public Long getConsumerID() {
              return consumerID;
       }

       /**
       * @param consumerID the consumerID to set
       */
       public void setConsumerID(Long consumerID) {
              this.consumerID = consumerID;
       }

       //--- For Virtual Column - Provide only Getters.
       /**
       * @return the isAdmin
       */
       public boolean isAdmin() {
              return isAdmin;
       }

}



--
III  Cheers!