Hibernate version:
Hibernate-Version: 3.2.4.sp1
I'm using JBoss 4.2.2.GA with a PostgreSQL database. I made a small project in Eclipse, which uses 4 jar/ear/wars and this works. I use JPA annotations on my entities, and with a persistence.xml in my jar everything works in my JBoss. But I wanted to use the Eclipse Tools to add a HQL editor to my evironment. So I make a Hibernate Configuration and I can choose between the Annotations type and the JPA type. But both work only partly.
If I choose the Annotations type there are no entities present in the Configuration sub-tree. The Session Factory sub-tree says:<Sessionfactory error: Could not locate TransactionManager>.
Only the Database sub-tree works and shows all my tables.
If I choose the JPA type it is the other way around. The Configuration sub-tree shows my entities correctly. But the Session Factory sub-tree says: <Sessionfactory error: Could not find datasource>
And the Database sub-tree shows an error popup with HibernateException: Could not find datasource. And if I look in the .log from Eclipse it gives me the stack trace I show here:
Quote:
!SUBENTRY 2 org.hibernate.eclipse.console 4 150 2008-02-14 14:53:42.346
!MESSAGE javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
!STACK 0
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at org.hibernate.console.ConsoleConfiguration$3.execute(ConsoleConfiguration.java:357)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:65)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:88)
at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:352)
at org.hibernate.eclipse.console.workbench.LazySessionFactoryAdapter.getChildren(LazySessionFactoryAdapter.java:41)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:97)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:103)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:196)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
At first I only had a persistence.xml file in my jar and everything worked in JBoss. I use a datasource file in my JBoss, which references the used database. This is the persistence.xml file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="eniglib" transaction-type="JTA">
<jta-data-source>java:/PostgresDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.transaction.factory_class"
value="org.hibernate.transaction.CMTTransactionFactory" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
Now I also have a hibernate.cfg.xml for the eclipse tools plugin, but only the database part which I described above started working through that.
This is the hibernate.cfg.xml file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="eniglib">
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">***</property>
<property name="hibernate.connection.url">jdbc:postgresql://192.168.1.37:5432/eniglib</property>
<property name="hibernate.connection.username">***</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
</session-factory>
</hibernate-configuration>
I also added a hibernate.properties file:
Code:
#hibernate.connection.datasource = java:/comp/env/jdbc/test
hibernate.connection.url = jdbc:postgresql://192.168.1.37:5432/eniglib
hibernate.connection.username = jboss
hibernate.connection.password = enigmatry
hibernate.transaction.factory_class = org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class = org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
I reference all files in the configuration used, except the persistence.xml, I did enter the persistence unit in the configuration, which is 'eniglib'.
Should I change something in my jta-data-source setting in the persistence.xml, so Eclipse can find the database without using JNDI?