Hello,
I am new to Hibernate and I am trying to learn by doing the tutorial
http://www.hibernate.org/hib_docs/v3/re ... stapp.html
It seems that there is nothing stored when I am trying out the tutorial. I assume that what is in the database should be listed when providing the "list" argument while executing. The only thing I see that differs is when I try to store evetns the SQL that is presented has this row
Code:
(null, ?, ?)
but should it really look like that, should
null be there? What is the problem and is there any other way to find out what is stored in the HSQLDB database?
Hibernate version: 3.3.1.ga
Mapping documents:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="events.Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="native"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
private void createAndStoreEvent(String title, Date theDate) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);
session.save(theEvent);
session.getTransaction().commit();
}
private List listEvents() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from Event").list();
session.getTransaction().commit();
return result;
}
}
Full stack trace of any exception that occurs:No stacktrace presented
Name and version of the database you are using:HSQLDB 1.8.0.10
The generated SQL (show_sql=true):When storing events:
Code:
Hibernate:
insert
into
EVENTS
(EVENT_ID, EVENT_DATE, title)
values
(null, ?, ?)
Hibernate:
call identity()
When trying to list events that has been stored:
Code:
Hibernate:
select
event0_.EVENT_ID as EVENT1_0_,
event0_.EVENT_DATE as EVENT2_0_,
event0_.title as title0_
from
EVENTS event0_
hibernate.cfg.xml:Code:
<?xml version="1.0"?><!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!--<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hb</property>
<property name="connection.username">root</property>
<property name="connection.password"></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="events/Event.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Thanks in advance!