I am using JBoss AS 7 with H2 database. I have a standalone application that tries to connect to this database like this.
My config file:
<?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 name="Test">
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.url">jdbc:h2:mem:test</property>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<mapping class="Kunde" resource="Kunde.hbm.xml"/>
<mapping class="Mitarbeiter" resource="Mitarbeiter.hbm.xml"/>
</session-factory>
</hibernate-configuration>
My mapping files are:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 26, 2012 7:34:15 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="Kunde" table="KUNDE">
<id name="id" type="long">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="vorname" type="java.lang.String">
<column name="VORNAME" />
</property>
<property name="nachname" type="java.lang.String">
<column name="NACHNAME" />
</property>
<property name="firma" type="java.lang.String">
<column name="FIRMA" />
</property>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 26, 2012 7:34:15 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="Mitarbeiter" table="MITARBEITER">
<id name="id" type="long">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="vorname" type="java.lang.String">
<column name="VORNAME" />
</property>
<property name="nachname" type="java.lang.String">
<column name="NACHNAME" />
</property>
</class>
</hibernate-mapping>
My entity classes:
public class Kunde {
long id;
String vorname;
String nachname;
String firma;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getVorname() {
return vorname;
}
public void setVorname(String vorname) {
this.vorname = vorname;
}
public String getNachname() {
return nachname;
}
public void setNachname(String nachname) {
this.nachname = nachname;
}
public String getFirma() {
return firma;
}
public void setFirma(String firma) {
this.firma = firma;
}
}
(The other one looks similar).
My test code:
public static void main(String[] args) {
try {
// This step will read hibernate.cfg.xml and prepare hibernate for
// use
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
SessionFactory sessionFactory = configuration
.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
// Create new instance of Kinde and set values in it by reading them
// from form object
System.out.println("Inserting Record");
Kunde kunde = new Kunde();
kunde.setId(1);
kunde.setVorname("A");
kunde.setNachname("N");
kunde.setFirma("Privat");
session.save(kunde);
System.out.println("Done");
// Actual insertion will happen at this step
session.flush();
session.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
Exception:
Okt 26, 2012 7:56:45 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Okt 26, 2012 7:56:45 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.0.1.Final}
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Kunde.hbm.xml
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Mitarbeiter.hbm.xml
Okt 26, 2012 7:56:45 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: Test
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [org.h2.Driver] at URL [jdbc:h2:mem:test]
Okt 26, 2012 7:56:45 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {}
Okt 26, 2012 7:56:46 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Okt 26, 2012 7:56:46 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
Okt 26, 2012 7:56:46 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Okt 26, 2012 7:56:46 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Any idea?
Update:
Stupid me :)
I printed the entire stack trace which revealed that my classpath was incomplete:
Caused by: java.lang.ClassNotFoundException: javassist.util.proxy.MethodFilter
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 23 more
I added the javaassist JAR and it is working fine now.
Sorry.
Probably you need to use javassistjar file; I used javassist-3.10.0.GA.jar and this error gone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With