Hibernate error in create entity manger [ java.lang.NoSuchMethodError: org.hibernate.cfg.Environment.verifyProperties(Ljava/util/Map;)V ] -
i'm using hibernate provider jpa in java ee 6 , jboss 7.1.1 final. searched solutions im new hibernate , don't fix issue. im getting error:
exception in thread "main" java.lang.nosuchmethoderror: org.hibernate.cfg.environment.verifyproperties(ljava/util/map;)v @ org.hibernate.boot.registry.standardserviceregistrybuilder.build(standardserviceregistrybuilder.java:278) @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl.<init>(entitymanagerfactorybuilderimpl.java:173) @ org.hibernate.jpa.boot.spi.bootstrap.getentitymanagerfactorybuilder(bootstrap.java:34) @ org.hibernate.jpa.hibernatepersistenceprovider.getentitymanagerfactorybuilder(hibernatepersistenceprovider.java:165) @ org.hibernate.jpa.hibernatepersistenceprovider.getentitymanagerfactorybuilderornull(hibernatepersistenceprovider.java:114) @ org.hibernate.jpa.hibernatepersistenceprovider.getentitymanagerfactorybuilderornull(hibernatepersistenceprovider.java:71) @ org.hibernate.jpa.hibernatepersistenceprovider.createentitymanagerfactory(hibernatepersistenceprovider.java:52) @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:78) @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:54) @ main.main(main.java:13) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ com.intellij.rt.execution.application.appmain.main(appmain.java:140)
my persistence.xml
<?xml version="1.0" encoding="utf-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="manager1" transaction-type="jta"> <provider>org.hibernate.ejb.hibernatepersistence</provider> <properties> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test_app"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.driver"/> <property name="hibernate.connection.username" value="test"/> <property name="hibernate.connection.password" value="test"/> <property name="hibernate.archive.autodetection" value="class"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hbm2ddl.auto" value="create-drop"/> <property name="hibernate.dialect" value="org.hibernate.dialect.mysqldialect"/> </properties> </persistence-unit> </persistence>
main class test connection db
public class main { public static void main(string[] args) { entitymanagerfactory emf = persistence.createentitymanagerfactory("manager1"); entitymanager em = emf.createentitymanager(); // ----- creating users entitytransaction t = em.gettransaction(); t.begin(); user usuario1 = new user(); usuario1.setuser_name("user1"); usuario1.setusermessage("text example 1"); em.persist(usuario1); user usuario2 = new user(); usuario2.setuser_name("user2"); usuario2.setuser_name("text example 2"); em.persist(usuario2); t.commit(); em.close(); emf.close(); }
}
my libs
my project folder structure
and 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>agenda5</groupid> <artifactid>agenda5</artifactid> <version>1.0-snapshot</version> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <hibernate-core.version>3.6.4.final</hibernate-core.version> <mysql-connector-java.version>5.1.16</mysql-connector-java.version> <slf4j.version>1.6.1</slf4j.version> <log4j.version>1.6.1</log4j.version> </properties> <dependencies> <!-- hibernate dependencies --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>${hibernate-core.version}</version> </dependency> <!-- mysql dependencies --> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>${mysql-connector-java.version}</version> </dependency> <!-- logging dependencies --> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-api</artifactid> <version>${slf4j.version}</version> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <version>${log4j.version}</version> </dependency> </dependencies> </project>
xml should below <persistence-unit name="manager1" transaction-type="jta"> <provider>org.hibernate.ejb.hibernatepersistence</provider> <properties> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test_app</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.driver</property <property name="hibernate.connection.username">test</property <property name="hibernate.connection.password">test</property <property name="hibernate.archive.autodetection">class</property <property name="hibernate.show_sql">true</property <property name="hibernate.format_sql">true</property <property name="hbm2ddl.auto">create-drop</property <property name="hibernate.dialect">org.hibernate.dialect.mysqldialect</property </properties> </persistence-unit> </persistence>
Comments
Post a Comment