java - NoSuchMethodError: javax.persistence.JoinColumn.ForeignKey -
this question has answer here:
- nosuchmethoderror: javax.persistence.joincolumn.foreignkey() 2 answers
- how fix nosuchmethoderror? 18 answers
when i'm trying run test (in fact it's empty , i'm using control building of test :)) i'm getting error:
caused by: java.lang.nosuchmethoderror: javax.persistence.joincolumn.foreignkey()ljavax/persistence/foreignkey; @ org.hibernate.cfg.annotationbinder.bindmanytoone(annotationbinder.java:2898) @ org.hibernate.cfg.annotationbinder.processelementannotations(annotationbinder.java:1742) @ org.hibernate.cfg.annotationbinder.processidpropertiesifnotalready(annotationbinder.java:906) @ org.hibernate.cfg.annotationbinder.bindclass(annotationbinder.java:733) @ org.hibernate.boot.model.source.internal.annotations.annotationmetadatasourceprocessorimpl.processentityhierarchies(annotationmetadatasourceprocessorimpl.java:245) @ org.hibernate.boot.model.process.spi.metadatabuildingprocess$1.processentityhierarchies(metadatabuildingprocess.java:222) @ org.hibernate.boot.model.process.spi.metadatabuildingprocess.complete(metadatabuildingprocess.java:265) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.metadata(entitymanagerfactorybuilderimpl.java:848) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.build(entitymanagerfactorybuilderimpl.java:876) @ org.hibernate.jpa.hibernatepersistenceprovider.createcontainerentitymanagerfactory(hibernatepersistenceprovider.java:135) @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:343) @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:319) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1637) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1574)
my pom.xml looks that:
<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>starterkit</groupid> <artifactid>gielda</artifactid> <version>0.0.1-snapshot</version> <properties> <java.version>1.8</java.version> <spring.framework.version>4.2.5.release</spring.framework.version> <junit.version>4.12</junit.version> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-aop</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context-support</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-test</artifactid> </dependency> <!-- http://mvnrepository.com/artifact/org.springframework/spring-tx --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-tx</artifactid> <version>4.2.5.release</version> </dependency> <!-- http://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa --> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-jpa</artifactid> <version>1.10.1.release</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>6.0.2</version> </dependency> <!-- http://mvnrepository.com/artifact/javax.el/el-api --> <dependency> <groupid>javax.el</groupid> <artifactid>el-api</artifactid> <version>2.2</version> </dependency> <!-- http://mvnrepository.com/artifact/org.glassfish.web/javax.el --> <dependency> <groupid>org.glassfish.web</groupid> <artifactid>javax.el</artifactid> <version>2.2.6</version> </dependency> <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-core --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>5.1.0.final</version> </dependency> <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-entitymanager</artifactid> <version>5.1.0.final</version> </dependency> <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-validator --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-validator</artifactid> <version>5.2.4.final</version> </dependency> <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-annotations --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-annotations</artifactid> <version>3.5.6-final</version> </dependency> <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate</artifactid> <version>3.5.4-final</version> <type>pom</type> </dependency> <!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-commons-annotations --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-commons-annotations</artifactid> <version>3.2.0.final</version> </dependency> <!-- http://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-api</artifactid> <version>1.7.19</version> </dependency> <!-- http://mvnrepository.com/artifact/org.slf4j/slf4j-simple --> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-simple</artifactid> <version>1.7.19</version> </dependency> <!-- http://mvnrepository.com/artifact/org.jadira.usertype/usertype.core --> <dependency> <groupid>org.jadira.usertype</groupid> <artifactid>usertype.core</artifactid> <version>5.0.0.ga</version> </dependency> <dependency> <groupid>org.jinq</groupid> <artifactid>jinq-jpa</artifactid> <version>1.6.2</version> </dependency> <!-- http://mvnrepository.com/artifact/org.hsqldb/hsqldb --> <dependency> <groupid>org.hsqldb</groupid> <artifactid>hsqldb</artifactid> <version>2.3.3</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>ma.glasnost.orika</groupid> <artifactid>orika-core</artifactid> <version>1.4.5</version> </dependency> </dependencies> <dependencymanagement> <dependencies> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-aop</artifactid> <version>${spring.framework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> <version>${spring.framework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>${spring.framework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context-support</artifactid> <version>${spring.framework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>${spring.framework.version}</version> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-test</artifactid> <version>${spring.framework.version}</version> <scope>test</scope> </dependency> </dependencies> </dependencymanagement> <build> <plugins> <plugin> <artifactid>maven-compiler-plugin</artifactid> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
and persistence.xml that:
<?xml version="1.0" encoding="utf-8"?> <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="gielda"> <class>pl.spring.demo.entity.kursentity</class> <class>pl.spring.demo.entity.spolkaentity</class> </persistence-unit> </persistence>
i've seen in other topics can caused version of javax.persistence or hibernate seems me, have both: persistence of version 2.1 , hibernate newer 4.3. know maybe how i'm still getting error?
my 2 entities:
package pl.spring.demo.entity; import java.io.serializable; import javax.persistence.*; import java.math.bigdecimal; import java.util.date; @entity @table(name="kursy") @namedquery(name="kursentity.findall", query="select k kursentity k") public class kursentity implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy=generationtype.auto) @column(name="id_kursu") private long idkursu; private bigdecimal cena; @temporal(temporaltype.date) @column(name="data_kursu") private date datakursu; //bi-directional many-to-one association spolkaentity @manytoone @joincolumn(name="nazwa_spolki") private spolkaentity spolki; public kursentity() { } public kursentity(long idkursu, bigdecimal cena, date datakursu, spolkaentity spolki) { this.idkursu = idkursu; this.cena = cena; this.datakursu = datakursu; this.spolki = spolki; } public long getidkursu() { return this.idkursu; } public void setidkursu(long idkursu) { this.idkursu = idkursu; } public bigdecimal getcena() { return this.cena; } public void setcena(bigdecimal cena) { this.cena = cena; } public date getdatakursu() { return this.datakursu; } public void setdatakursu(date datakursu) { this.datakursu = datakursu; } public spolkaentity getspolki() { return this.spolki; } public void setspolki(spolkaentity spolki) { this.spolki = spolki; } }
and
package pl.spring.demo.entity; import java.io.serializable; import javax.persistence.*; import java.util.list; @entity @table(name="spolki") @namedquery(name="spolkaentity.findall", query="select s spolkaentity s") public class spolkaentity implements serializable { private static final long serialversionuid = 1l; @id private string nazwa; //bi-directional many-to-one association kursentity @onetomany(mappedby="spolki") private list<kursentity> kursy; public spolkaentity() { } public spolkaentity(string nazwa, list<kursentity> kursy) { this.nazwa = nazwa; this.kursy = kursy; } public string getnazwa() { return this.nazwa; } public void setnazwa(string nazwa) { this.nazwa = nazwa; } public list<kursentity> getkursy() { return this.kursy; } public void setkursy(list<kursentity> kursy) { this.kursy = kursy; } public kursentity addkursy(kursentity kursy) { getkursy().add(kursy); kursy.setspolki(this); return kursy; } public kursentity removekursy(kursentity kursy) { getkursy().remove(kursy); kursy.setspolki(null); return kursy; } }
database-context.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config /> <context:component-scan base-package="pl.spring.demo.entity" /> <jpa:repositories base-package="pl.spring.demo.repository" /> <tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager"> <property name="entitymanagerfactory" ref="entitymanagerfactory" /> </bean> <!--<util:properties id="hsqldbjpaprops"location="classpath:/test_data_access/hsqldb_jpa.properties" /> --> <!--<jdbc:embedded-database id="datasource" type="hsql" /> --> <bean name="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="com.mysql.jdbc.driver" /> <property name="url" value="jdbc:mysql://localhost:3306/gielda" /> <property name="username" value="root" /> <property name="password" value="starterkit" /> </bean> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> <property name="packagestoscan" value="pl.spring.demo.entity" /> <property name="datasource" ref="datasource" /> <property name="jpaproperties"> <props> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</prop> </props> </property> <property name="persistenceprovider"> <bean class="org.hibernate.jpa.hibernatepersistenceprovider"> </bean> </property> </bean> </beans>
Comments
Post a Comment