Guys I am trying to read an excel file and save informations to database in a spring application but i am facing with this error. Here's my work below! (I did not share my controller etc. I just need to save them database after that I will work on spring.
Main Spring Application
package com.javainuse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SpringBootHelloWorldApplication {
public static void main(String[] args) throws IOException {
System.out.println("Debug Print");
Read();
SpringApplication.run(SpringBootHelloWorldApplication.class, args);
}
private static void Read() throws IOException {
System.out.println("Debug print");
SessionFactory sf = new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();
Session session = sf.openSession();
FileInputStream file = new FileInputStream(new File("C:/Users/MONSTER/Desktop/Hello.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
Row row;
for(int i=1; i<=sheet.getLastRowNum(); i++){
row = (Row) sheet.getRow(i); //sheet number
String id;
if( row.getCell(0)==null) { id = "0"; }
else id= row.getCell(0).toString();
String name;
if( row.getCell(1)==null) { name = "null";}
else name = row.getCell(1).toString(); //else copies cell data to name variable
String phone;
if( row.getCell(2)==null) { phone = "null"; }
else phone = row.getCell(2).toString();
Transaction t = session.beginTransaction();
Customer std = new Customer();
std.setId((int) Double.parseDouble(id));
std.setName(name);
std.setPhone(phone);
System.out.println(std.getId()+" "+std.getName()+" "+std.getPhone());
session.saveOrUpdate(std);
t.commit();
}
file.close();
System.out.println("Completed!");
}
}
I am trying to read excel and save data before the spring starts.
My customer class
package com.javainuse;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="customer", schema="excel")
public class Customer {
#Id
// #GeneratedValue(strategy = GenerationType.AUTO)
private int id;
#Column
private String name;
#Column
private String phone;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public Customer(int id, String name, String phone) {
super();
this.id = id;
this.name = name;
this.phone = phone;
}
public Customer() {
super();
}
}
Hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/excel</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<mapping class="com.javainuse.Customer"/>
</session-factory>
</hibernate-configuration>
Error
Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:973)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
at com.javainuse.SpringBootHelloWorldApplication.Read(SpringBootHelloWorldApplication.java:31)
at com.javainuse.SpringBootHelloWorldApplication.main(SpringBootHelloWorldApplication.java:22)
14:05:19.071 [pool-1-thread-1] DEBUG org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - Connection pool now considered primed; min-size will be maintained
Thanks!
Try the below solution.
Update Hibernate JPA to 2.1 and It works.
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
seems like its a hibernate persistence version problem ...just update your persistence library..it should solve the error
Related
I'm learning Hibernates and while practising I came across this strange problem. Sometimes, when I do my changes and run the program, all of a sudden my Eclipse console gets stuck showing the last line as Hibernate: drop table UserDetails. To get the program running I need to restart my Eclipse program.
Below is my code.
UserDetails.java
package org.hibernates.dto;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
#Entity
public class UserDetails {
#Id
#Column(name = "User_ID")
private int userId;
#Column(name = "User_Name")
private String userName;
#Temporal(TemporalType.TIME)
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getDesription() {
return desription;
}
public void setDesription(String desription) {
this.desription = desription;
}
#Lob
private String address;
private String desription;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
HibernatesTest.java
package org.hibernates.dto;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernatesTest {
public static void main(String[] args) {
UserDetails user = new UserDetails();
user.setUserId(1);
user.setUserName("User 1");
user.setDate(new Date());
user.setAddress("User Address");
user.setDesription("User Desription");
Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder builder = (StandardServiceRegistryBuilder) new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = builder.build();
SessionFactory factory = configuration.buildSessionFactory(serviceRegistry);
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
session.save(user);
tx.commit();
session.close();
}
}
hibernate.cfg.xml
<!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>
<!-- Database connection settings -->
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://U0138039-TPD-A\\SQLEXPRESS:1433;DatabaseName=HibernatesDataBase</property>
<property name="connection.username">sa</property>
<property name="connection.password">T!ger123</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServer2005Dialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Names the annotated entity class -->
<mapping class="org.hibernates.dto.UserDetails" />
</session-factory>
</hibernate-configuration>
How can I fix this?
You need to close the session factory
factory.close()
I get this error while trying to make test query for my Database. I refer to the java class instead of table name but it doesn't help. Added mapping to cfg.xml too but without success. What can be the cause?
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/michal
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
root
</property>
<property name="hibernate.hbm2ddl.auto">
</property>
<!-- List of XML mapping files -->
<mapping package="regularmikey.DatabaseSingleton"/>
<mapping class="regularmikey.DatabaseSingleton.Product" />
</session-factory>
</hibernate-configuration>
Product.java
package regularmikey.DatabaseSingleton;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "product")
public class Product {
#Column(name = "id")
#Id #GeneratedValue
private String id;
#Column(name = "name")
private String name;
#Column(name = "alloy")
private String alloy;
#Column(name = "weight")
private String weight;
#Column(name = "min_temp")
private String min_temp;
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 getAlloy() {
return alloy;
}
public void setAlloy(String alloy) {
this.alloy = alloy;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getMin_temp() {
return min_temp;
}
public void setMin_temp(String min_temp) {
this.min_temp = min_temp;
}
}
DBSession.java
package regularmikey.DatabaseSingleton;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class DBSession {
private static DBSession dbSession = null;
private SessionFactory sessionFactory = null;
private DBSession(){
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
sessionFactory = (configuration.buildSessionFactory(serviceRegistry));
};
public static DBSession getInstance()
{
if(dbSession == null) {
dbSession = new DBSession();
}
return dbSession;
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
}
App.java
package regularmikey.DatabaseSingleton;
import java.util.Iterator;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class App
{
public static void main( String[] args )
{
DBSession dbFactory = DBSession.getInstance();
Session session = dbFactory.getSessionFactory().openSession();
Transaction tx = null;
try{
tx = session.beginTransaction();
List products = session.createQuery("FROM Product").list();
for (Iterator iterator =
products.iterator(); iterator.hasNext();){
Product product = (Product) iterator.next();
System.out.print("Name: " + product.getName());
System.out.print("Alloy: " + product.getAlloy());
System.out.println("Weight: " + product.getWeight());
}
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
}finally {
session.close();
}
}
}
My question might look a easy and silly but I'm unable to find solution so thought of sharing the problem here... I'm getting an Exception in a simple Hibernate code running in Java perspective!! I've added JTA or transaction jar files but it's not helping!
package com.demo.bean;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
#Entity
#Table(name="emp_details")
public class Employee{
#Id
#Column(name="emp_id")
private int id;
#Column(name="emp_name")
private String name;
private String address;
private int phone;
private double salary;
#Lob
private String description;
#Temporal(TemporalType.DATE)
private Date doj;
public Date getDoj() {
return doj;
}
public void setDoj(Date doj) {
this.doj = doj;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getPhone() {
return phone;
}
public void setPhone(int phone) {
this.phone = phone;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
package com.demo.client;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.demo.bean.Employee;
public class HibernateClient {
public static void main(String[] args) {
Employee emp = new Employee();
emp.setId(333);
emp.setName("Guru");
emp.setAddress("Bangalore");
emp.setSalary(56565.0);
emp.setDescription("Hello");
emp.setDoj(new Date());
Configuration cfg = new Configuration();
cfg.configure("resource/hibernate.cfg.xml");
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(emp);
tx.commit();
sessionFactory.close();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!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="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/becm3createDatabaseIfNotExist=true</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping class="com.demo.bean.Employee"/>
</session-factory>
</hibernate-configuration>
I am new to the concepts of hibernate and annotations .Currently I am making program on collections in hibernate.
Actually following is code of my program
person.class
package com;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "PesonSubjects")
public class Person {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
#ElementCollection
private Set<Subjects> subjectList = new HashSet<Subjects>();
public Set<Subjects> getSubjectList() {
return subjectList;
}
public void setSubjectList(Set<Subjects> subjectList) {
this.subjectList = subjectList;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
MAIN class
package com;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class Personmain {
/**
* #param args
*/
public static void main(String[] args) {
SessionFactory sessionfactory = new AnnotationConfiguration()
.configure().buildSessionFactory();
Session session = sessionfactory.openSession();
session.beginTransaction();
Person person = new Person();
person.setName("vikram");
Subjects subjects1 = new Subjects();
subjects1.setAuthor("xxxxxxxx");
subjects1.setISBN(10111);
subjects1.setName("mein kampf");
subjects1.setPublicationHouse("tmh");
person.getSubjectList().add(subjects1);
Subjects subjects2 = new Subjects();
subjects2.setAuthor("bbbbb");
subjects2.setISBN(10112);
subjects2.setName("harry porter");
subjects2.setPublicationHouse("William");
person.getSubjectList().add(subjects2);
session.save(person);
session.getTransaction().commit();
session.close();
}
}
subjects class
package com;
import javax.persistence.Embeddable;
#Embeddable
public class Subjects {
private int ISBN;
private String name;
private String Author;
private String publicationHouse;
public int getISBN() {
return ISBN;
}
public void setISBN(int iSBN) {
ISBN = iSBN;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return Author;
}
public void setAuthor(String author) {
Author = author;
}
public String getPublicationHouse() {
return publicationHouse;
}
public void setPublicationHouse(String publicationHouse) {
this.publicationHouse = publicationHouse;
}
}
my configuration file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/AnnotationCollections</property>
<property name="connection.username">root</property>
<property name="connection.password">cccccccc</property>
<property name="hbm2ddl.auto">create</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<mapping class="com.Person" />
</session-factory>
</hibernate-configuration>
Now through the program I want a collection of subjects to enter into a table (I am not annotating subjectList as i want it to be collection and not in tabular format)
ie it should store values in collection fomat
However I am getting the following error
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(subjectList)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:410)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1099)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1284)
at com.Personmain.main(Personmain.java:14)
Is there something else to define ??
Thanks
For security's sake, keep both classes mapped:
<mapping class="com.Person" />
<mapping class="com.Subjects" />
Besides that, your code seems to be inferring the wrong access type.
Try adding:
#javax.persistence.Access(javax.persistence.AccessType.FIELD)
to Person. Like:
#Entity
#Table(name = "PesonSubjects")
#javax.persistence.Access(javax.persistence.AccessType.FIELD)
public class Person {
If that does not work, try adding to both Person and Subjects.
I have a problem with hibernate envers. I added the eventlisteners and I added the #Audited Annotation, but when I change the name (or anything else) there are no revisions in the database created. I hope you can help me.
This is the Main class where I build the session etc.
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
Configuration configuration = new Configuration().configure();
ServiceRegistryBuilder registry = new ServiceRegistryBuilder();
registry.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = registry.buildServiceRegistry();
SessionFactory sessionFactory = configuration
.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
Address address1 = new Address();
address1.setStreetName("Privet Drive");
address1.setHouseNumber(4);
Person person1 = new Person();
person1.setName("Hi");
person1.setSurname("test");
person1.setAddress(address1);
session.beginTransaction();
session.persist(person1);
session.persist(address1);
session.getTransaction().commit();
person1.setName("Hans");
session.beginTransaction();
session.persist(person1);
session.persist(address1);
session.getTransaction().commit();
session.close();
}
}
Here the Person class:
package Main;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RevisionEntity;
import org.hibernate.envers.RevisionNumber;
import org.hibernate.envers.RevisionTimestamp;
#Entity
#Table(name="PERSON")
#Audited
public class Person{
#Id
#GeneratedValue
#RevisionNumber
private int id;
private String name;
private String surname;
private String username;
#ManyToOne
private Address address;
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public Address getAddress() {
return address;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setSurname(String surname) {
this.surname = surname;
}
public void setAddress(Address address) {
this.address = address;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
The adress:
package Main;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.envers.Audited;
#Entity
#Table(name="ADDRESS")
#Audited
public class Address {
#Id
#GeneratedValue
private int id;
private String streetName;
private Integer houseNumber;
private Integer flatNumber;
#OneToMany(mappedBy = "address")
private Set<Person> persons;
public int getId() {
return id;
}
public String getStreetName() {
return streetName;
}
public Integer getHouseNumber() {
return houseNumber;
}
public Integer getFlatNumber() {
return flatNumber;
}
public Set<Person> getPersons() {
return persons;
}
public void setId(int id) {
this.id = id;
}
public void setStreetName(String streetName) {
this.streetName = streetName;
}
public void setHouseNumber(Integer houseNumber) {
this.houseNumber = houseNumber;
}
public void setFlatNumber(Integer flatNumber) {
this.flatNumber = flatNumber;
}
public void setPersons(Set<Person> persons) {
this.persons = persons;
}
}
And my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/hwdb2</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hbm2ddl.auto">create</property>
<property name="hibernate.ejb.event.post-insert">org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.post-update">org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.post-delete">org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.pre-collection-update">org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.pre-collection-remove">org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.post-collection-recreate">org.hibernate.envers.event.AuditEventListener</property>
<!-- Mapping files -->
<mapping class="Main.Person" />
<mapping class="Main.Address" />
<mapping class="Main.ExampleListener" />
</session-factory>
</hibernate-configuration>
I hope you have a solution for me. Many thanks!
I finally updated to Hibernate 4.1.8 and the problem is solved. I had the wrong envers version which seemed to be not compatible with the hibernate version I used.