I'll have to make a db connection with JNDI to Hibernate.
Can anybody help me to find out what is wrong in my source.
my properties:
Code:
hibernate.connection.datasource = java:/comp/env/jdbc/jndiUrlaubsplaner
hibernate.jndi.url = jdbc:oracle:thin:@AT-LXAUSW01.benteler.net:1521:wsphprod
hibernate.connection.username = urlaubsplaner
hibernate.connection.password = urlaubsplaner
hibernate.transaction.factory_class = \
org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class = \
org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
my sessionbuild:
Code:
private SessionFactory _sessionFactory;
private Session _session;
private ThreadLocal _threadLocal = new ThreadLocal();
// Template Methods
protected abstract String getKeyFieldName();
protected abstract Class getStoredClass();
// Methods
protected AbstractServiceDBImpl() {
// initalizeHibernate();
if (! isHibernateInitialized())
initalizeHibernate();
}
protected Session getSession() throws HibernateException {
Contract.require(isHibernateInitialized(), "hibernate ist initialisiert");
Session session = (Session) _threadLocal.get();
if (session == null || !session.isOpen()) {
session = _sessionFactory.openSession();
_threadLocal.set(session);
}
/*try {
int i = 0;
System.out.println(">>> session.connection().isClosed() " + session.connection().isClosed());
} catch (HibernateException e) {
System.out.println("Probleme beim connect");
//e.printStackTrace();
} catch (SQLException e) {
System.out.println("Probleme beim connect");
//e.printStackTrace();
}*/
session.clear();
Contract.ensure(session != null, "result");
return session;
}
private boolean sessionIsConnected()
{
// return _session.isConnected();
return ((Session) _threadLocal.get()).isConnected();
}
protected boolean isHibernateInitialized() {
return _sessionFactory != null;
}
/**
* Hibernate initialisieren. SessionFactory merken.
*/
private void initalizeHibernate() {
Contract.require(!isHibernateInitialized(), "Hibernate is not initialized yet");
try
{
// Konfigurationsdateien einlesen
URL mappingURL = getClass().getClassLoader().getResource("mapping.xml");
InputStream in = getClass().getClassLoader().getResourceAsStream("hibernate.properties");
Properties properties = new Properties();
properties.load(in);
System.out.println("test3");
// Hibernate konfigurieren
Configuration configuration = new Configuration();
configuration.setProperties(properties);
configuration.addURL(mappingURL);
System.out.println("test4");
// SessionFactory merken! Sie erzeugt die benötigten Sessions.
_sessionFactory = configuration.buildSessionFactory();
}
catch (HibernateException e)
{
System.out.println("Probleme beim Konfigurieren von Hibernate!");
e.printStackTrace();
}
catch (IOException e)
{
System.out.println("Probleme beim Zugriff auf die Datei hibernate.properties");
e.printStackTrace();
}
Contract.ensure(isHibernateInitialized(), "Hibernate is successfully initialized");
}
my main problem:
Quote:
[17.07.06 08:25:17:594 CEST] 544b4b1d DatasourceCon F org.hibernate.connection.DatasourceConnectionProvider Could not find datasource: java:/comp/env/jdbc/jndiUrlaubsplaner
[17.07.06 08:25:17:594 CEST] 544b4b1d DatasourceCon F org.hibernate.connection.DatasourceConnectionProvider TRAS0014I: Die folgende Ausnahmebedingung wurde protokolliert: javax.naming.NameNotFoundException: Name not found in context "java:".