Reputation: 599
Error message
Oct 20, 2015 10:56:33 PM org.hibernate.dialect.Dialect INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect Oct 20, 2015 10:56:33 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
I know that are several questions here about this, but as stated on most of them they request to make sure that I am using hibernate 4.3+ and JPA2.1+. And I believe that I am using both of them:
Here is my persistence.xml
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="web" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/web"/>
<property name="javax.persistence.jdbc.user" value="postgresUser"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.password" value="admin"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.ejb.entitymanager_factory_name" value="web" />
</properties>
</persistence-unit>
</persistence>
Here is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.utfpr</groupId>
<artifactId>ProjetoWeb</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ProjetoWeb</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.torpedoquery</groupId>
<artifactId>org.torpedoquery</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.2-1002-jdbc4</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Finally here is one example of a BarEntity
@Entity
public class BarEntity implements Serializable {
@Id
@GeneratedValue
private long id;
@ManyToOne
@JoinColumn(name = "fooId", referencedColumnName = "id")
@Cascade({CascadeType.SAVE_UPDATE})
private Foo foo;
@Column(nullable = false, unique = true)
private String bar;
@Column(nullable = false)
private String foobar;
}
What can I do to deploy this?
I am sorry for not being able to reduce the pom.xml / persistence.xml into more generic, as I am not sure where is the error.
Upvotes: 2
Views: 5393
Reputation: 7004
As stated by both Zhao and hermitmaster this is definitely a dependency problem. But, I believe that it could be hard for someone with little experience to figure what should match / could be wrong.
So, here is a how to inspect this
The relevant data in pom.xml
is:
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
(...)
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
(...)
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.0.2.Final</version>
As stated by the user he got it right that hibernate needs to be 4.3 or higher. However, it should be using the same version of hibernate and jpamodelgen.
Both hibernate-entitymanager and hibernate-jpamodelgen should have the same number. Be it:
4.3.1
or 5.0.2
.
Upvotes: 3
Reputation: 42596
It usually means that the version of the library you are using is not compatible with the one you really depends on. Please check the version of javax.persistence.JoinColumn.foreignKey() library or the one who is using this library to make sure you are using the correct version of them.
Upvotes: 3