Hibernate version:
2.1.6
Mapping documents:
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-2.0.dtd">
<hibernate-configuration>
<session-factory name="java:/hibernate/HibernateFactory">
<property name="show_sql">true</property>
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/sale</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<mapping resource="hibernatemaps/sale/Employee.hbm.xml" />
</session-factory>
</hibernate-configuration>
Employee.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="org.interactive.interactive.integration.sale.entity.Employee" table="Employee">
<id name="employeeId" column="employee_id" type="long">
<generator class="assigned" />
</id>
<property name="name" column="name" />
<property name="password" column="password" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
I use HibernateUtil.java in reference:
The method I call it is:
public void testHibernate() {
logger.debug("CompileTestMgrEJB testHibernate() start");
Transaction transaction = null;
try {
Session session = HibernateUtil.currentSession();
transaction = session.beginTransaction();
Employee employee = new Employee();
employee.setEmployeeId(new Long(1000));
employee.setName("Test");
employee.setPassword("Test");
session.save(employee);
transaction.commit();
HibernateUtil.closeSession();
} catch (Exception ex) {
try {
transaction.rollback();
} catch (HibernateException e) {
logger.debug("CompileTestMgrEJB testHibernate() HibernateException");
}
logger.debug("CompileTestMgrEJB testHibernate() Exception: ");
ex.printStackTrace();
}
logger.debug("CompileTestMgrEJB testHibernate() end");
}
Full stack trace of any exception that occurs:
[SettingsFactory] INFO : Use scrollable result sets: true
[SettingsFactory] INFO : Use JDBC3 getGeneratedKeys(): true
[SettingsFactory] INFO : Optimize cache for minimal puts: false
[SettingsFactory] INFO : echoing all SQL to stdout
[SettingsFactory] INFO : Query language substitutions: {}
[SettingsFactory] INFO : cache provider: net.sf.hibernate.cache.EhCacheProvider
[Configuration] INFO : instantiating and configuring caches
[HibernateUtil] ERROR: Initial SessionFactory creation failed.
java.lang.IllegalAccessError
at net.sf.cglib.core.ClassEmitter.setTarget(ClassEmitter.java:47)
at net.sf.cglib.core.ClassEmitter.<init>(ClassEmitter.java:39)
at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:165)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:236)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:791)
at org.interactive.interactive.common.util.HibernateUtil.<clinit>(HibernateUtil.java:18)
at org.interactive.interactive.business.test.CompileTestMgrEJB.testHibernate(CompileTestMgrEJB.java:78)
at org.interactive.interactive.business.test.CompileTestMgr_bfazjd_EOImpl.testHibernate(CompileTestMgr_bfazjd_EOImpl.java:45)
at org.interactive.interactive.business.test.CompileTestMgrDel.testHibernate(CompileTestMgrDel.java:31)
at org.interactive.interactive.presentation.sale.SaleAction.testHibernate(SaleAction.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
java.rmi.RemoteException: EJB Exception: ; nested exception is:
java.lang.ExceptionInInitializerError
at weblogic.ejb20.internal.EJBRuntimeUtils.throwRemoteException(EJBRuntimeUtils.java:102)
at weblogic.ejb20.internal.BaseEJBHome.handleSystemException(BaseEJBHome.java:307)
at weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:263)
at weblogic.ejb20.internal.StatelessEJBObject.postInvoke(StatelessEJBObject.java:140)
at org.interactive.interactive.business.test.CompileTestMgr_bfazjd_EOImpl.testHibernate(CompileTestMgr_bfazjd_EOImpl.java:55)
at org.interactive.interactive.business.test.CompileTestMgrDel.testHibernate(CompileTestMgrDel.java:31)
at org.interactive.interactive.presentation.sale.SaleAction.testHibernate(SaleAction.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
Caused by: java.lang.ExceptionInInitializerError
at org.interactive.interactive.common.util.HibernateUtil.<clinit>(HibernateUtil.java:21)
at org.interactive.interactive.business.test.CompileTestMgrEJB.testHibernate(CompileTestMgrEJB.java:78)
at org.interactive.interactive.business.test.CompileTestMgr_bfazjd_EOImpl.testHibernate(CompileTestMgr_bfazjd_EOImpl.java:45)
... 24 more
Caused by: java.lang.IllegalAccessError
at net.sf.cglib.core.ClassEmitter.setTarget(ClassEmitter.java:47)
at net.sf.cglib.core.ClassEmitter.<init>(ClassEmitter.java:39)
at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:165)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:236)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:791)
at org.interactive.interactive.common.util.HibernateUtil.<clinit>(HibernateUtil.java:18)
... 26 more
Name and version of the database you are using:
MySQL 4.0.2
Debug level Hibernate log excerpt:
[Configuration] INFO : configuring from resource: /hibernate.cfg.xml
[Configuration] INFO : Configuration resource: /hibernate.cfg.xml
[Configuration] DEBUG: show_sql=true
[Configuration] DEBUG: connection.driver_class=org.gjt.mm.mysql.Driver
[Configuration] DEBUG: connection.url=jdbc:mysql://localhost:3306/sale
[Configuration] DEBUG: connection.username=root
[Configuration] DEBUG: connection.password=
[Configuration] DEBUG: dialect=net.sf.hibernate.dialect.MySQLDialect
[Configuration] DEBUG: java:/hibernate/HibernateFactory<-org.dom4j.tree.DefaultAttribute@1095fd7 [Attribute: name resource value "hibernatemaps/sale/Employee.hbm.xml"]
[Configuration] INFO : Mapping resource: hibernatemaps/sale/Employee.hbm.xml
[Binder] INFO : Mapping class: org.interactive.interactive.integration.sale.entity.Employee -> Employee
[Binder] DEBUG: Mapped property: employeeId -> employee_id, type: long
[Binder] DEBUG: Mapped property: name -> name, type: string
[Binder] DEBUG: Mapped property: password -> password, type: string
[DriverManagerConnectionProvider] DEBUG: total checked-out connections: 0
[DriverManagerConnectionProvider] DEBUG: opening new JDBC connection
[DriverManagerConnectionProvider] DEBUG: created connection to: jdbc:mysql://localhost:3306/sale, Isolation Level: 4
[DriverManagerConnectionProvider] DEBUG: returning connection to pool, pool size: 1
|