Search code examples
javahibernatejpamaven-3weblogic11g

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?


Solution

  • 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