jpa - Error: java.lang.NoSuchMethodError in Hibernate 4.3.5.final core -
there similar question: here i'm not using spring , jpa. also, i've tried solution , don't have success. hibernate version different too.
problem: ear project ejb 3.1 , hibernate 4.3.5.final no jpa, using hibernate core (mysql).
the deployed project up, no errors in deploy.
after created 2 entity's using @manytoone
mapping, i'm getting error:
java.lang.nosuchmethoderror: javax.persistence.joincolumn.foreignkey()ljavax/persistence/foreignkey; org.hibernate.cfg.annotationbinder.bindmanytoone(annotationbinder.java:2881) org.hibernate.cfg.annotationbinder.processelementannotations(annotationbinder.java:1795) org.hibernate.cfg.annotationbinder.processidpropertiesifnotalready(annotationbinder.java:963) org.hibernate.cfg.annotationbinder.bindclass(annotationbinder.java:796) org.hibernate.cfg.configuration$metadatasourcequeue.processannotatedclassesqueue(configuration.java:3788)
(the error long, if want stacktrace, please tell.)
here 2 entity's created, , then, error appeared:
package br.gov.xyz.malotes.model; import javax.persistence.cascadetype; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.manytoone; import org.hibernate.annotations.genericgenerator; @entity public class usuario { @id @genericgenerator(name="gen",strategy="increment") @generatedvalue(generator="gen") @column(name = "id", unique = true, nullable = false, precision = 15, scale = 0) private int id; private string nome; private string login; private string senha; @manytoone//(cascade = cascadetype.all) // tirar cascata aqui agrante que tabela unidade nao seja alterada sem querer @joincolumn(name="unidade_id") private unidade unidade; public unidade getunidade() { return unidade; } public void setunidade(unidade unidade) { this.unidade = unidade; } public int getid() { return id; } public void setid(int id) { this.id = id; } public string getnome() { return nome; } public void setnome(string nome) { this.nome = nome; } public string getlogin() { return login; } public void setlogin(string login) { this.login = login; } public string getsenha() { return senha; } public void setsenha(string senha) { this.senha = senha; } }
the other entity:
package br.gov.xyz.malotes.model; import java.util.set; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.id; import javax.persistence.onetomany; import javax.persistence.table; import org.hibernate.annotations.genericgenerator; @entity public class unidade { @id @genericgenerator(name="gen",strategy="increment") @generatedvalue(generator="gen") @column(name = "id", unique = true, nullable = false, precision = 15, scale = 0) private int id; @onetomany(mappedby="unidade") private set<usuario> usuario; private string nome; private string endereco; public set<usuario> getusuario() { return usuario; } public void setusuario(set<usuario> usuario) { this.usuario = usuario; } public void setid(int id) { this.id = id; } public string getnome() { return nome; } public void setnome(string nome) { this.nome = nome; } public string getendereco() { return endereco; } public void setendereco(string endereco) { this.endereco = endereco; } }
if necessary, here pom.xml in maven:
<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/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <parent> <artifactid>malotes</artifactid> <groupid>br.gov.xyz</groupid> <version>0.1</version> </parent> <artifactid>malotes-ejb</artifactid> <packaging>ejb</packaging> <name>malotes ejb module</name> <dependencies> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>4.3.5.final</version> </dependency> <!-- declare apis depend on , need compilation. of them provided jboss 7 --> <!-- import ejb api, use provided scope api included in jboss 7 --> <dependency> <groupid>org.jboss.spec.javax.ejb</groupid> <artifactid>jboss-ejb-api_3.1_spec</artifactid> <scope>provided</scope> </dependency> <!-- import cdi api, use provided scope api included in jboss 7 --> <dependency> <groupid>javax.enterprise</groupid> <artifactid>cdi-api</artifactid> <scope>provided</scope> </dependency> <dependency> <groupid>org.hibernate.javax.persistence</groupid> <artifactid>hibernate-jpa-2.1-api</artifactid> <version>1.0.0.final</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.6</version> </dependency> <!-- test scope dependencies --> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> </dependency> <!-- optional, highly recommended --> <!-- arquillian allows test enterprise code such ejbs , transactional(jta) jpa junit/testng --> </dependencies> <build> <plugins> <plugin> <artifactid>maven-ejb-plugin</artifactid> <version>2.3</version> <configuration> <!-- tell maven using ejb 3.1 --> <ejbversion>3.1</ejbversion> </configuration> </plugin> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>2.3.2</version> <executions> <execution> <id>default-testcompile</id> <phase>test-compile</phase> <goals> <goal>testcompile</goal> </goals> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </execution> <execution> <id>default-compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </execution> </executions> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> <profiles> <profile> <!-- default profile skips tests, though can tune run unit tests based on custom pattern --> <!-- seperate profiles provided running tests, including arquillian tests execute in specified container --> <id>default</id> <activation> <activebydefault>true</activebydefault> </activation> <build> <plugins> <plugin> <artifactid>maven-surefire-plugin</artifactid> <version>2.4.3</version> <configuration> <skip>true</skip> </configuration> </plugin> </plugins> </build> </profile> <profile> <!-- add jboss repository need jboss connectors arquillian --> <repositories> <!-- jboss community public repository composite repository of several major repositories --> <!-- see http://community.jboss.org/wiki/mavengettingstarted-users --> <repository> <id>jboss-public-repository</id> <name>jboss repository</name> <url>http://repository.jboss.org/nexus/content/groups/public</url> <!-- these optional flags designed speed builds reducing remote server calls --> <releases> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginrepositories> <pluginrepository> <id>jboss-public-repository</id> <name>jboss repository</name> <url>http://repository.jboss.org/nexus/content/groups/public</url> <releases> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginrepository> </pluginrepositories> <!-- optional arquillian testing profile executes tests in jboss instance --> <!-- profile start new jboss instance, , execute test, shutting down when done --> <!-- run with: mvn clean test -parq-jbossas-managed --> <id>arq-jbossas-managed</id> <dependencies> <dependency> <groupid>org.jboss.as</groupid> <artifactid>jboss-as-arquillian-container-managed</artifactid> <version>7.0.2.final</version> <scope>test</scope> </dependency> </dependencies> </profile> <profile> <!-- add jboss repository need jboss connectors arquillian --> <repositories> <!-- jboss community public repository composite repository of several major repositories --> <!-- see http://community.jboss.org/wiki/mavengettingstarted-users --> <repository> <id>jboss-public-repository</id> <name>jboss repository</name> <url>http://repository.jboss.org/nexus/content/groups/public</url> <!-- these optional flags designed speed builds reducing remote server calls --> <releases> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginrepositories> <pluginrepository> <id>jboss-public-repository</id> <name>jboss repository</name> <url>http://repository.jboss.org/nexus/content/groups/public</url> <releases> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginrepository> </pluginrepositories> <!-- optional arquillian testing profile executes tests in remote jboss instance --> <!-- run with: mvn clean test -parq-jbossas-remote --> <id>arq-jbossas-remote</id> <dependencies> <dependency> <groupid>org.jboss.as</groupid> <artifactid>jboss-as-arquillian-container-remote</artifactid> <version>7.0.2.final</version> <scope>test</scope> </dependency> </dependencies> </profile> </profiles> </project>
can me find solution?
the solution upgrade jpa 2.0 jpa 2.1 module of jboss 7.1.1 final. upgrade:
1 - download jpa 2.1 ---no generic hibernate here: maven spec hibernate jpa 2.1
2 - put jar downloaded here : jboss-as-7.1.1.final/modules/javax/persistence/api/main
or if using enterprise jboss (eap) put jar folder instead: jboss-eap-6.4.0\modules\system\layers\base\javax\persistence\api\main
(like lukman commented)
3 - edit module.xml in same dir use jar downloaded, these:
<resources> <resource-root path="hibernate-jpa-2.1-api-1.0.0.final.jar"/> </resources>
4 - restart jboss
dont have sure; seems jpa 2.0 doesnt have javax.persistence.joincolumn.foreignkey() method. trying code in jpa 2.1 way; jboss factory uses jpa 2.0 built in instead
Comments
Post a Comment