Hi guys! currently we're using hibernate 2.1.0 and its working fine. here's my mapping:
hibernate.hbm.xml
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<!-- for mysql -->
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<!-- Mapping files -->
<mapping resource="hbm/Profession.hbm.xml"/>
<mapping resource="hbm/Sector.hbm.xml"/>
<mapping resource="hbm/ListingRole.hbm.xml"/>
<mapping resource="hbm/ListingType.hbm.xml"/>
<mapping resource="hbm/Industry.hbm.xml"/>
<mapping resource="hbm/ContactRole.hbm.xml"/>
<mapping resource="hbm/ListingEntry.hbm.xml"/>
<mapping resource="hbm/ListingSub.hbm.xml"/>
<mapping resource="hbm/ListingHeader.hbm.xml"/>
<mapping resource="hbm/Title.hbm.xml"/>
<mapping resource="hbm/ContactRelationship.hbm.xml"/>
<mapping resource="hbm/Contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
and stored in the folder /hbm (together with the class mappings)
I created a class called SQLManager that loads the configuration file and also responsible in creating the session
SQLManager.java
/*
* Created on Nov 21, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.eon.common;
import java.net.URL;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.eon.cms.tools.Util;
import com.eon.common.exception.DBException;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
/**
*
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class SQLManager {
private static final String CONFIGFILE = "/hbm/hibernate.hbm.xml";
private String _configFilePath = null;
private static SQLManager _manager = null;
private SessionFactory _factory = null;
private DataSource _datasource = null;
private Configuration configuration = null;
private boolean isStandAlone = false;
private SQLManager() {
}
public void init() {
URL configFileURL = null;
try {
configFileURL = SQLManager.class.getResource(
(_configFilePath==null)?CONFIGFILE:_configFilePath);
configuration = new Configuration().configure(configFileURL);
_factory = configuration.buildSessionFactory();
Util.getLogger(this)
.debug("open connection "+_factory.openSession().isConnected());
} catch (HibernateException he) {
he.printStackTrace();
}
}
public void createTables() {
/* try {
new SchemaExport(configuration).create(true, true);
Util.getLogger(this).debug("Generated the Database");
} catch (HibernateException he) {
he.printStackTrace();
}*/
}
public static SQLManager getInstance() {
if (_manager == null)
_manager = new SQLManager();
return _manager;
}
public void setSessionFactory(SessionFactory sf) {
_factory = sf;
}
public SessionFactory getSessionFactory(){
return _factory;
}
public Session getSession() throws HibernateException,SQLException {
if (_datasource == null)
return _factory.openSession();
else {
Util.getLogger(this).debug("new connection");
return _factory.openSession(_datasource.getConnection());
}
}
public void setDataSource(DataSource datasource) {
_datasource = datasource;
}
............
}
Here's the problem, when we migrated to hibernate2.1.2 im getting this error:
junit.framework.AssertionFailedError: Exception in constructor: testTree (java.lang.NoClassDefFoundError: net/sf/cglib/beans/BulkBeanException
at net.sf.hibernate.util.ReflectHelper.getBulkBean(ReflectHelper.java:154)
at net.sf.hibernate.type.ComponentType.<init>(ComponentType.java:110)
at net.sf.hibernate.cfg.Binder.bindComponent(Binder.java:886)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:280)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1229)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:285)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:315)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:973)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:928)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:871)
at com.eon.common.SQLManager.init(SQLManager.java:51)
at TestTool.<init>(TestTool.java:33)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at junit.framework.TestSuite.createTest(TestSuite.java:135)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
at junit.framework.TestSuite.<init>(TestSuite.java:75)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.getTest(RemoteTestRunner.java:331)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:369)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
)
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestSuite$1.runTest(TestSuite.java:263)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
and its complaining on this line:
configuration = new Configuration().configure(configFileURL); ???
We want to migrate to the new version because of its new features but is hibernate2.1.2 stable already?Any help guys?
thanks...
raymond
|