Sahil Dave
Sahil Dave

Reputation: 353

Weblogic11g - java.lang.NoSuchMethodError: javax.persistence.OneToOne.orphanRemoval()z

I know this question has been asked quite a few times over here, but none of the solutions seemed to worked for me. Pardon me for asking this one again as I am new to both maven and hibernate.

hibernate dependency in pom.xml

<hibernate.version>4.2.0.Final</hibernate.version>

<dependency>
 <groupId>org.hibernate</groupId>
 <artifactId>hibernate-entitymanager</artifactId>
 <version>${hibernate.version}</version>
</dependency>

<dependency>
 <groupId>org.hibernate</groupId>
 <artifactId>hibernate-validator</artifactId>
 <version>${hibernate.version}</version>
</dependency>

This gives me following jars:

hibernate-entitymanager-4.2.0.Final
hibernate-core-4.2.0.Final
hibernate-validator-4.2.0.Final
hibernate-jpa-2.0-api-1.0.1.Final

I also have:

hibernate-commons-annotations-4.0.1.Final

But I am not sure how I got it.

I am using the one-to-one relationship for a Category - Product relationship.

@Entity
@Table(name="Products")
public class Product {
   @Id    
   @Column(name="id")
   @GeneratedValue
   int productId;

   @NotEmpty
   @Length(max=50)
   @Column(name="name")
   String name;

   @Column(name="category_id")
   int categoryId;

   @OneToOne
   @ForeignKey(name="categoryId")
   private Category category;

   // getters and setters

}

Edit:

Since it is clear that Weblogic 11g jpa jar is taking precedence over the 'hibernate-jpa-2.0-api'. Should I fallback to an older version of hibernate that uses jpa-1.0 or is there a way I can enforce weblogic to use 'hibernate-jpa-2.0-api' instead of its jpa jar?

Upvotes: 1

Views: 8506

Answers (3)

Diego Montoya
Diego Montoya

Reputation: 139

I was facing the same problem and I had to hack weblogic.

That's what I did:

First edit the file that starts weblogic server (startWebLogic.cmd), this is located in a path like:

C:\Users{username}\AppData\Roaming\JDeveloper\system11.1.2.0.38.60.17\DefaultDomain\bin and add this lines in the line 6 of the file. SETLOCAL

    @REM Hack JPA begin
    echo Hack JPA begin
    set wls_modules=C:\oracle\Middleware\modules
    set PRE_CLASSPATH=%wls_modules%\javax.persistence_1.0.0.0_2-0-0.jar;%wls_modules%\com.oracle.jpa2support_1.0.0.0_2-0.jar;
    echo PRE_CLASSPATH=%PRE_CLASSPATH%
    echo Hack JPA End
    @REM Hack JPA END

That way you override the libs that weblogic use in JPA.

After that, modify the JPA provider in the weblogic console:

  • in the browser go to weblogic console, normally its running in localhost:7101/console
  • Go to "JTA"
  • Select the "JPA" tab
  • In the "Default JPA Provider" select "Kodo"
  • Restart weblogic server

In that way weblogic uses the new libs defined which had the correct version of the Class

Upvotes: 1

Nimpo
Nimpo

Reputation: 444

I had the same pbl and i solved it by removing persistence-api-1.0.jar & ejb3-persistence.jar and adding javax.persistence-2.0.0.jar.

Upvotes: 1

cmbaxter
cmbaxter

Reputation: 35453

I think the better question to ask is if you have any unneeded jars in your classpath instead of if you have anything missing. Getting a NoSuchMethodError generally means you have one library that needs a particular version of another library and the version it ends up using at runtime is not the right version. In your case, I would look for ejb3-persistence.jar on your classpath as it seems the error has something to do with the OneToOne annotation. Wih hibernate, you should be getting this from hibernate-jpa-2.0-api-1.0.1.Final but my guess is that you also have the OneToOne annotation class file coming from another jar.

Also, it seems as if someone else has already encountered a similar issue. See if this helps:

java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z

Also, since it seems you are using Weblogic 11g which is a JavaEE5 server and not compatible with JavaEE6 which is what the hibernate-jpa-2.0 jar is trying to use. If you are going to deploy to weblogic 11g, you need to find a version of hibernate that is compatible with it and I don't think 4.2.0 Final is.

Weblogic 11g and JavaEE 6

Upvotes: 2

Related Questions