3

I am new in Websphere application server. Please let me know where I am doing wrong. I am getting java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;

I have checked google but maximum answers are telling to use Hibernate 4.3.X version and JPA 2.1 version. I am using the same version. If I removing the JPA jar and adding javax.persistence jar then I am getting Namespace method not found.

My Project is using JSF,EJB and JPA(Hibernate).

As I traced it is giving at this line of code

SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());

I am using sql server 2012 as a database

Thanks in advance

Jars I am using

antlr-2.7.7
com.ibm.mqjms
hibernate-commons-annotations-4.0.5.Final
hibernate-entitymanager-4.3.8.Final
hibernate-core-4.3.8.Final
hibernate-jpa-2.1-api-1.0.0.Final
jandex-1.1.0.Final
jasper
jasper-compiler-jdt
javax.ejb
javax.faces-2.1.7
javax.jms
javax.mail-1.4.4
javax.servlet
javax-inject
jsf-api-2.2.5
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Gourav Bhatia
  • 186
  • 1
  • 11
  • Did you add APIs like `javax.servlet`, `javax.ejb`, `javax-inject` on your own to your project? They are available in the container itself and not supposed to be added. – Tiny Jan 21 '15 at 08:52
  • Yes I have added, While faces this issue I have added all this jar separately. I have tried in both way. But facing same error again and again.. – Gourav Bhatia Jan 21 '15 at 09:17

1 Answers1

6

WebSphere has built in JPA 2.0 provider (OpenJPA) and the JoinColumn.foreignKey() is available from 2.1. If you must use JPA 2.1 and Hibernate you have to override default JPA provider. See Using third-party persistence providers for more details.

You will have to add the <provider> element to the persistence.xml to specify explicitly which persistence provider to use and set classloader for your application to PARENT_LAST.

Gas
  • 17,601
  • 4
  • 46
  • 93
  • @Tommy You should also always consider platform capabilities before starting coding and selecting frameworks. If you code to for example Java EE 6, then compliant servers already are providing all you need, without adding bunch of various libraries to your application. Try not to code for web container, as your application gets bigger and usually there are framework integration issues. – Gas Jan 22 '15 at 12:05
  • 1
    @Gas I am so angry at my team right now because we are dealing with this same WebSphere pain when I warned them about using Tomcat. Nobody listens to me – maple_shaft Jun 09 '15 at 11:13
  • @maple_shaft, yes, one should always use the deployment platform for development. But some will never listen... Especially now, when WebSphere for Developers is freely available, and if you want lightweight server you can use [WebSphere Liberty](https://developer.ibm.com/wasdev/websphere-liberty/), which is as lightweight as Tomcat, and compatible with full WAS (except Java EE 7 features for a moment). – Gas Jun 09 '15 at 12:37
  • You guys have GOT to be kidding me. Websphere takes a ridiculous amount of time to install and configure for each developer. Running it in an environment with best practices such as jenkins continuous integration is too difficult. You COULD have your developers use websphere, but the productivity cost is too high. You are far better off using an embedded container for development then working through the issues on your target appserver. – David Parish Sep 22 '15 at 18:44