I'm trying to learn Hibernate and got through using an EJB container with hsqldb in the "Java Persistence with Hibernate' book. I then decided to convert to postgresql. I got it working with the first two example but when I try to use an EJB container (JBoss) I am having problems with the JNDI context when trying to deploy the schema.
Any help would be greatly appreciated.
version of Hibernate: 3.3.1
version of Postgresql 8.3
persistence.xml
--------------------
<persistence 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/ ... ce_1_0.xsd" version="1.0">
<persistence-unit name="helloworld">
<!-- A datasource managed by the Java EE runtime environment -->
<jta-data-source>java:comp/env/jdbc/HelloWorldDS</jta-data-source>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<!-- SQL stdout logging
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="use_sql_comments" value="true"/>
-->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<!-- On deployment of this persistence unit, drop and then re-create all tables -->
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
</persistence>
HelloWorld-beans.xml
-----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
xmlns="urn:jboss:bean-deployer:2.0">
<!-- Enable a JCA datasource available through JNDI -->
<bean name="helloWorldDatasourceFactory"
class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
<property name="jndiName">java:comp/env/jdbc/HelloWorldDS</property>
<!-- HSQL DB -->
<property name="driverClass">org.postgresql.Driver</property>
<property name="connectionURL">jdbc:postgresql://localhost/rlaw</property>
<property name="userName">rlaw</property>
<property name="password">password</property>
<property name="newConnectionSql>select 1</property>
<property name="minSize">0</property>
<property name="maxSize">10</property>
<property name="blockingTimeout">1000</property>
<property name="idleTimeout">100000</property>
<property name="transactionManager"><inject bean="TransactionManager"/></property>
<property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
<property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
</bean>
<bean name="HelloWorldDS" class="java.lang.Object">
<constructor factoryMethod="getDatasource">
<factory bean="helloWorldDatasourceFactory"/>
</constructor>
</bean>
</deployment>
trace
----------------
Buildfile: build.xml
clean:
[delete] Deleting directory /home/rlaw/workspace/HelloWorld/bin
[mkdir] Created dir: /home/rlaw/workspace/HelloWorld/bin
compile:
[javac] Compiling 4 source files to /home/rlaw/workspace/HelloWorld/bin
copymetafiles:
[copy] Copying 7 files to /home/rlaw/workspace/HelloWorld/bin
schemaexport:
[hibernatetool] Executing Hibernate Tool with a JPA Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] 22:27:12,593 INFO Version:15 - Hibernate Annotations 3.4.0.GA
[hibernatetool] 22:27:12,610 INFO Environment:543 - Hibernate 3.3.0.SP1
[hibernatetool] 22:27:12,615 INFO Environment:576 - hibernate.properties not found
[hibernatetool] 22:27:12,627 INFO Environment:709 - Bytecode provider name : javassist
[hibernatetool] 22:27:12,639 INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
[hibernatetool] 22:27:12,763 INFO Version:16 - Hibernate EntityManager 3.4.0.GA
[hibernatetool] 22:27:13,302 INFO AnnotationBinder:419 - Binding entity from annotated class: hello.Message
[hibernatetool] 22:27:13,348 INFO EntityBinder:422 - Bind entity hello.Message on table MESSAGES
[hibernatetool] 22:27:13,515 INFO Version:17 - Hibernate Validator 3.1.0.GA
[hibernatetool] 22:27:13,660 INFO Version:15 - Hibernate Tools 3.2.2.GA
[hibernatetool] 22:27:13,689 INFO Dialect:175 - Using dialect: org.hibernate.dialect.PostgreSQLDialect
[hibernatetool] 22:27:13,781 INFO SchemaExport:226 - Running hbm2ddl schema export
[hibernatetool] 22:27:13,782 INFO SchemaExport:246 - writing generated schema to file: /home/rlaw/workspace/HelloWorld/helloworld-ddl.sql
[hibernatetool] 22:27:13,784 INFO SchemaExport:251 - exporting generated schema to database
[hibernatetool] 22:27:13,789 INFO NamingHelper:49 - JNDI InitialContext properties:{}
[hibernatetool] 22:27:13,862 ERROR NamingHelper:56 - Could not obtain initial context
[hibernatetool] javax.naming.NamingException: Local server is not initialized
[hibernatetool] at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
[hibernatetool] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
[hibernatetool] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
[hibernatetool] at javax.naming.InitialContext.init(InitialContext.java:223)
[hibernatetool] at javax.naming.InitialContext.<init>(InitialContext.java:175)
[hibernatetool] at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:51)
[hibernatetool] at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
[hibernatetool] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
[hibernatetool] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:79)
[hibernatetool] at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:51)