Hi!
I'm trying to run Hibernate in a standealone application with the Threadlocal pattern (HibernateUtil). But i want to keep it simple and so i don't want to use an appserver with JNDI. When i start my Testapplication, it throws a "Could not bind factory to JNDI" Warning and exits. I did _not_ configure a hibernate.session_factory_name in my xml properties but when it comes to reading the hibernate.xfg.xml, suddenly a session_factory_name is configured (look at the logging file)
How can I tell Hibernate _not_ to use JNDI and _not_ set a session_factory_name when useing the Treadlocal Pattern with a HibernateUtil?
Hibernate version: Hibernate 3.0.5
Mapping documents:
<?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>
<!-- configuration for ora10vm3_compadre -->
<session-factory>
<!-- shared properties -->
<property name="hibernate.show_sql">false</property>
<property name="hibernate.use_outer_join">true</property>
<property name="jta.UserTransaction">java:comp/UserTransaction/</property>
<property name="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="hibernate.connection.url">url</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.statement_cache.size">25</property>
<property name="hibernate.session_factory_name"></property>
<!-- hier muss noch ein geeigneter Connectionpool konfiguriert werden -> C3PO -->
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
</session-factory>
</hibernate-configuration>
My Hibernateutil
public class HibernateUtil {
private static final SessionFactory sessionFactory = null;
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
static Logger logger = Logger.getRootLogger();
static {
SimpleLayout layout = new SimpleLayout();
FileAppender fileAppender = null;
try {
fileAppender = new FileAppender( layout, "Compadre.log", false );
} catch (IOException e) {
throw new CompadreException(e);
}
logger.addAppender( fileAppender );
// ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF:
logger.setLevel( Level.DEBUG );
Configuration cfg = new Configuration();
cfg.addClass(Appserver.class);
cfg.addClass(Atom.class);
cfg.addClass(Atomtosetofatoms.class);
cfg.addClass(Atomtype.class);
cfg.addClass(Block.class);
/** AND 70 More ... */
SessionFactory sessionFactory = cfg.configure().buildSessionFactory();
}
/**
* Gibt die Session des aktuellen Threads zurueck, oder macht eine neue
* Session auf
*
* @return Session
*/
public static Session getSession() {
// session dieses Threads holen
Session s = (Session) threadSession.get();
// neue Session aufmachen, falls dieser Thread noch keine hat
try {
if (s == null) {
s = sessionFactory.openSession();
threadSession.set(s);
}
} catch (HibernateException e) {
// TODO Handle Exception
}
return s;
}
/**
* Schliesst die Session des aktuellen Threads
*/
public static void closeSession() {
try {
Session s = (Session) threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen()) {
s.close();
}
} catch (HibernateException e) {
// TODO: handle exception
}
}
/**
* Startet im aktuellen Thread eine neue Transaction, oder setzt eine
* vorhandene fort
*/
public static void beginTransaction() {
Transaction tx = (Transaction) threadTransaction.get();
try {
if (tx == null) {
tx = getSession().beginTransaction();
threadTransaction.set(tx);
}
} catch (HibernateException e) {
// TODO: handle exception
}
}
/**
* Führt an der Transaction des aktuellen Threads ein Commit aus
*/
public static void commitTransaction() {
Transaction tx = (Transaction) threadTransaction.get();
try {
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
tx.commit();
threadTransaction.set(null);
}
} catch (HibernateException e) {
// TODO: handle exception
rollbackTransaction();
}
}
/**
* Führt an der Transaction des aktuellen Threads ein Rollback aus
*/
public static void rollbackTransaction() {
Transaction tx = (Transaction) threadTransaction.get();
try {
threadTransaction.set(null);
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
tx.rollback();
}
} catch (HibernateException e) {
// TODO: handle exception
} finally {
closeSession();
}
}
}
The logging file
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
DEBUG - trying to locate
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
DEBUG - found
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
DEBUG - hibernate.connection.username=usename
DEBUG - hibernate.connection.password=pword
DEBUG - hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
DEBUG - hibernate.connection.url=url
DEBUG - hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
INFO - Configured SessionFactory: Compadre <- this is the name of my application. i don't know why hibernate uses this name as sessionfactory name.
DEBUG - properties: {hibernate.connection.password=passw, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\bin, java.vm.version=1.4.2_03-b02, hibernate.connection.username=compadre, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=DE, sun.os.patch.level=Service Pack 1, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\Programme\eclipse31\workspace\CompadreSampleData, java.runtime.version=1.4.2_03-b02, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOKUME~1\sidobeue\LOKALE~1\Temp\1\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows 2003, sun.java2d.fontpath=, java.library.path=C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\bin\client;C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\bin;C:\oracle\product\10.1.0\ora10vm3\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Programme\Sun\AppServer\bin, java.specification.name=Java Platform API Specification, java.class.version=48.0, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.2, user.home=C:\Dokumente und Einstellungen\sidobeue, user.timezone=, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.4, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, user.name=sidobeue, java.class.path=C:\Programme\eclipse31\workspace\CompadreSampleData\bin;C:\Programme\eclipse31\workspace\Compadre\bin;C:\Programme\eclipse31\workspace\Compadre\lib\ojdbc14.jar;C:\Programme\eclipse31\workspace\Compadre\lib\ant-1.6.3.jar;C:\Programme\eclipse31\workspace\Compadre\lib\ant-antlr-1.6.3.jar;C:\Programme\eclipse31\workspace\Compadre\lib\ant-junit-1.6.3.jar;C:\Programme\eclipse31\workspace\Compadre\lib\ant-launcher-1.6.3.jar;C:\Programme\eclipse31\workspace\Compadre\lib\antlr-2.7.5H3.jar;C:\Programme\eclipse31\workspace\Compadre\lib\ant-swing-1.6.3.jar;C:\Programme\eclipse31\workspace\Compadre\lib\asm.jar;C:\Programme\eclipse31\workspace\Compadre\lib\asm-attrs.jar;C:\Programme\eclipse31\workspace\Compadre\lib\c3p0-0.8.5.2.jar;C:\Programme\eclipse31\workspace\Compadre\lib\cglib-2.1.jar;C:\Programme\eclipse31\workspace\Compadre\lib\cleanimports.jar;C:\Programme\eclipse31\workspace\Compadre\lib\commons-collections-2.1.1.jar;C:\Programme\eclipse31\workspace\Compadre\lib\commons-lang-2.0.jar;C:\Programme\eclipse31\workspace\Compadre\lib\commons-logging-1.0.4.jar;C:\Programme\eclipse31\workspace\Compadre\lib\concurrent-1.3.2.jar;C:\Programme\eclipse31\workspace\Compadre\lib\connector.jar;C:\Programme\eclipse31\workspace\Compadre\lib\dom4j-1.6.jar;C:\Programme\eclipse31\workspace\Compadre\lib\ehcache-1.1.jar;C:\Programme\eclipse31\workspace\Compadre\lib\hibernate3.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jaas.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jacc-1_0-fr.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jaxen-1.1-beta-4.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jboss-cache.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jboss-common.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jboss-jmx.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jboss-system.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jdbc2_0-stdext.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jgroups-2.2.7.jar;C:\Programme\eclipse31\workspace\Compadre\lib\jta.jar;C:\Programme\eclipse31\workspace\Compadre\lib\junit-3.8.1.jar;C:\Programme\eclipse31\workspace\Compadre\lib\oscache-2.1.jar;C:\Programme\eclipse31\workspace\Compadre\lib\proxool-0.8.3.jar;C:\Programme\eclipse31\workspace\Compadre\lib\swarmcache-1.0rc2.jar;C:\Programme\eclipse31\workspace\Compadre\lib\versioncheck.jar;C:\Programme\eclipse31\workspace\Compadre\lib\xerces-2.6.2.jar;C:\Programme\eclipse31\workspace\Compadre\lib\xml-apis.jar;C:\Programme\eclipse31\workspace\Compadre\lib\log4j-1.2.9.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\ant-1.6.3.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\ant-antlr-1.6.3.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\ant-junit-1.6.3.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\ant-launcher-1.6.3.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\antlr-2.7.5H3.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\ant-swing-1.6.3.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\asm.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\asm-attrs.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\c3p0-0.8.5.2.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\cglib-2.1.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\cleanimports.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\commons-collections-2.1.1.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\commons-lang-2.0.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\commons-logging-1.0.4.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\concurrent-1.3.2.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\connector.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\dom4j-1.6.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\ehcache-1.1.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\hibernate3.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jaas.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jacc-1_0-fr.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jaxen-1.1-beta-4.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jboss-cache.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jboss-common.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jboss-jmx.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jboss-system.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jdbc2_0-stdext.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jgroups-2.2.7.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\jta.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\junit-3.8.1.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\ojdbc14.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\oscache-2.1.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\proxool-0.8.3.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\swarmcache-1.0rc2.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\versioncheck.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\xerces-2.6.2.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\xml-apis.jar;C:\Programme\eclipse31\workspace\CompadreSampleData\lib\log4j-1.2.9.jar, java.vm.specification.version=1.0, java.home=C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2, sun.arch.data.model=32, hibernate.connection.url=url, hibernate.dialect=org.hibernate.dialect.Oracle9Dialect, user.language=de, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, java.version=1.4.2_03, java.ext.dirs=C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\lib\ext, sun.boot.class.path=C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\lib\rt.jar;C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\lib\i18n.jar;C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\lib\sunrsasign.jar;C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\lib\jsse.jar;C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\lib\jce.jar;C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\lib\charsets.jar;C:\oracle\product\10.1.0\ora10vm3\jre\1.4.2\classes, java.vendor=Sun Microsystems Inc., file.separator=\,
hibernate.session_factory_name=Compadre, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.cpu.isalist=pentium i486 i386}