Je suis essayer de configurer mon application web de printemps avec Hibernate OGM pour mongoDB avec java 1.6 et OGM 4.1.3.Final.Hibernate OGM IncompatibleClassChangeError
Pour la session I, écrivez HibernateUtil.java qui fonctionne correctement avec le test JUnit mais il lance Exception.
Hibernate.java
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.ogm.cfg.OgmConfiguration;
public class HibernateUtil {
private static final Logger log = Logger.getLogger(HibernateUtil.class.getName());
private static final SessionFactory sessionFactory;
private static final StandardServiceRegistry serviceRegistry;
static {
try {
// create a new instance of OmgConfiguration
OgmConfiguration cfgogm = new OgmConfiguration();
// process configuration and mapping files
cfgogm.configure("hibernate_mongoDB.cfg.xml");
// create the SessionFactory
//cfgogm.getProperties();
serviceRegistry = (StandardServiceRegistry) new StandardServiceRegistryBuilder()
.applySettings(cfgogm.getProperties()).build();
sessionFactory = cfgogm.buildSessionFactory(serviceRegistry);
} catch (Exception ex) {
log.log(Level.SEVERE, "Initial SessionFactory creation failed !",
ex);
throw new EdumissException(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
TestMongoDb.java
package mkcl.os.test;
import java.util.Date;
import java.util.List;
import mkcl.os.apps.edumiss.utilities.HibernateUtil;
import org.hibernate.Query;
import org.hibernate.Session;
import org.junit.Test;
public class TestMongoDB {@
Test
public void testMongoDB() {
Session session = HibernateUtil.getSessionFactory().openSession();
try {
Players player = new Players();
player.setId("2");
player.setAge((short) 24);
player.setBirth(new Date());
player.setName("Pankaj");
player.setSurname("Saboo");
session.beginTransaction();
session.save(player);
session.getTransaction().commit();
String hql = "FROM Players";
Query query = session.createQuery(hql);
List results = query.list();
//List results = cr.list();
for (Object object: results) {
System.out.println("Data : " + object);
}
//session.flush(); // flush happens automatically anyway
} catch (RuntimeException re) {
session.getTransaction().rollback();
throw re;
} finally {
session.close();
}
}
}
Players.java
package mkcl.os.test;
import java.util.Date;
public class Players {
private String id;
@Override
public String toString() {
return "Players [id=" + id + ", name=" + name + ", surname=" + surname
+ ", age=" + age + ", birth=" + birth + ", getId()=" + getId()
+ ", getName()=" + getName() + ", getSurname()=" + getSurname()
+ ", getAge()=" + getAge() + ", getBirth()=" + getBirth()
+ ", getClass()=" + getClass() + ", hashCode()=" + hashCode()
+ ", toString()=" + super.toString() + "]";
}
private String name;
private String surname;
private short age;
private Date birth;
public Players() {
super();
// TODO Auto-generated constructor stub
}
public Players(String id, String name, String surname, short age, Date birth) {
super();
this.id = id;
this.name = name;
this.surname = surname;
this.age = age;
this.birth = birth;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public short getAge() {
return age;
}
public void setAge(short age) {
this.age = age;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
}
Players.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 5, 2014 4:06:20 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="mkcl.os.test.Players" table="PLAYERS">
<id name="id" type="java.lang.String">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="surname" type="java.lang.String">
<column name="SURNAME" />
</property>
<property name="age" type="short">
<column name="AGE" />
</property>
<property name="birth" type="java.util.Date">
<column name="BIRTH" />
</property>
</class>
</hibernate-mapping>
hibernate_mongoDB.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- <!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> -->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.ogm.datastore.provider">mongodb</property>
<!-- <property name="hibernate.ogm.datastore.grid_dialect">org.hibernate.ogm.datastore.mongodb.MongoDBDialect</property> -->
<property name="hibernate.ogm.datastore.database">yourdb</property>
<property name="hibernate.ogm.datastore.host">localhost</property>
<property name="hibernate.ogm.datastore.port">27017</property>
<property name="hibernate.ogm.datastore.create_database">true</property>
<mapping resource="mkcl/os/test/Players.hbm.xml"/>
</session-factory>
</hibernate-configuration>
pom.xml
dépendances utilisées pour sont OGM
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<version>4.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.12.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-core</artifactId>
<version>4.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>4.1</version>
</dependency>
Après le déploiement sur Tomcat je frappe par un autre jsp que le temps HibernateUtil.java renvoie une exception à ligne suivante
OgmConfiguration cfgogm = new OgmConfiguration();
Ex Line est ception
java.lang.IncompatibleClassChangeError: classe org.parboiled.transform.ClassNodeInitializer possède une interface org.objectweb.asm.ClassVisitor en tant que super classe
S'il vous plaît aidez-moi à résoudre ce problème. Merci à l'avance
ne fonctionne pas ... :( –
toujours obtenir la même erreur? .S'il vous plaît fournir la toute la version de jar – Zia
Obtenir la même erreur ... –