I got the following problem: I want to persist classes that are inside a Jar-File.
This is the way I tried to get things to work. Maybe someone yould comment, if this is the way Hibernate is supposed to be used.
I put the classes files (i.e. mypath/SomeClass.class) inside the jar with the path part (mypath/).
I put the configuration files under the same paths inside the Jar (i.e. /myPath/SomeClass.hbm.xml).
I put the hibernate.cfg.xml inside the Jar in the root path.
Inside my program I configure the session factory like this:
Code:
Configuration cfg = new Configuration();
File jar = new File("c:\\myJar.jar");
cfg.addJar(jar);
cfg.configure();
sessionFactory = cfg.buildSessionFactory();
Unfornunately I always get the error:
INFO net.sf.hibernate.cfg.Configuration - Searching for mapping documents in jar: myJar.jar
INFO net.sf.hibernate.cfg.Configuration - Found mapping documents in jar: myPath/SomeClass.hbm.xml
INFO net.sf.hibernate.cfg.Binder - Mapping class: myPath.SomeClass -> SOMECLASS
INFO net.sf.hibernate.cfg.Configuration - Configured SessionFactory: null
INFO net.sf.hibernate.cfg.Configuration - processing one-to-many association mappings
INFO net.sf.hibernate.cfg.Configuration - processing one-to-one association property references
INFO net.sf.hibernate.cfg.Configuration - processing foreign key constraints
INFO net.sf.hibernate.dialect.Dialect - Using dialect: net.sf.hibernate.dialect.MySQLDialect
INFO net.sf.hibernate.cfg.SettingsFactory - Use outer join fetching: true
INFO net.sf.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
INFO net.sf.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
INFO net.sf.hibernate.connection.DriverManagerConnectionProvider - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/neu
INFO net.sf.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=}
INFO net.sf.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
INFO net.sf.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
INFO net.sf.hibernate.cfg.SettingsFactory - Use scrollable result sets: true
INFO net.sf.hibernate.cfg.SettingsFactory - Use JDBC3 getGeneratedKeys(): true
INFO net.sf.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: false
INFO net.sf.hibernate.cfg.SettingsFactory - echoing all SQL to stdout
INFO net.sf.hibernate.cfg.SettingsFactory - Query language substitutions: {}
INFO net.sf.hibernate.cfg.SettingsFactory - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
INFO net.sf.hibernate.cfg.Configuration - instantiating and configuring caches
INFO net.sf.hibernate.impl.SessionFactoryImpl - building session factory
INFO net.sf.hibernate.util.ReflectHelper - reflection optimizer disabled for: mypath.SomeClass, CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
Can someone give me a hint what I going wrong or give me a better way how to use hibernate?
Thanks in advance.
Mike
P.S:
Hibernate Version: 2.1.5
Database: MySQL 4.0.20a (but shouldn't play a role)
Mapping file looks like this:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="myPath.SomeClass" table="SOMECLASS">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="someProperty" type="string"/>
</class>
</hibernate-mapping>