I am using Hibernate with an
hsqldb database. I had the following hibernate.cfg.xml
Code:
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:file:P://databases//miniDB</property>
<property name="connection.username">dbuser</property>
<property name="connection.password">secret</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="/com/corejsf/pojos/Book.hbm.xml"/>
<mapping resource="/com/corejsf/pojos/Event.hbm.xml"/>
<mapping resource="/com/corejsf/pojos/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I have managed to create 2 pojos and store data in the appropriate tables.
The problem is that when
Tomcat shutdowns my data are lost.Why is this happening? After searching a lot in the Internet I saw that I have not defined a property for datasource in the above configuration file.So I add the following line:
Code:
<property name="connection.datasource">java:comp/env/jdbc/TestDB</property>
. And next I add in the server.xml in the Tomcat directory the following line:
Code:
<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"/>
Now when the application starts I have the following exception:
Code:
Caused by: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:768)
at org.apache.naming.NamingContext.lookup(NamingContext.java:138)
at org.apache.naming.NamingContext.lookup(NamingContext.java:779)
at org.apache.naming.NamingContext.lookup(NamingContext.java:138)
at org.apache.naming.NamingContext.lookup(NamingContext.java:779)
at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
Can you please gine some guidelines. Why I have to define a datasource in my hibernate.cfg.xml since I provide a connection.url? Does this omition has anything to do with the fact that after I shutdown Tomcat I lose my data in the database?
Thanking you in advance.