I followed the hibernate tutorial chap-1 but there are no instructions to create the table EVENTS in HSQLDB so I created it using instructions from sourceforge. But still I am unable to run the first example. Please advice!!!!!
Hibernate version:3.2
Mapping documents:
<?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():
package events;
import org.hibernate.Session;
import util.HibernateUtil;
import java.util.Date;
public class EventManager {
public static void main(String args[]) {
EventManager mgr = new EventManager();
if(args[0].equals("store")){
mgr.createAndStoreEvent("My Event", new Date());
}
// HibernateUtil.getSessionFactory.close();
}
public void createAndStoreEvent(String title, Date date) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(date);
session.save(theEvent);
session.getTransaction().commit();
}
}
Full stack trace of any exception that occurs:
[java] 23:18:44,734 INFO Environment:514 - Hibernate 3.2.5
[java] 23:18:44,750 INFO Environment:532 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.hsqldb.jdbcDriver, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=sa, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:hsqldb:./build/db/hsqldb/hibernate, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
[java] 23:18:44,750 INFO Environment:563 - using java.io streams to persist binary types
[java] 23:18:44,750 INFO Environment:681 - Bytecode provider name : cglib
[java] 23:18:44,750 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
[java] 23:18:44,781 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
[java] 23:18:44,781 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
[java] 23:18:44,921 DEBUG DTDEntityResolver:38 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
[java] 23:18:44,921 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
[java] 23:18:44,921 DEBUG DTDEntityResolver:50 - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
[java] 23:18:44,937 DEBUG Configuration:1387 - connection.driver_class=org.hsqldb.jdbcDriver
[java] 23:18:44,937 DEBUG Configuration:1387 - connection.url=jdbc:hsqldb:hsql://localhost
[java] 23:18:44,937 DEBUG Configuration:1387 - connection.username=sa
[java] 23:18:44,937 DEBUG Configuration:1387 - connection.password=
[java] 23:18:44,937 DEBUG Configuration:1387 - connection.pool_size=1
[java] 23:18:44,937 DEBUG Configuration:1387 - dialect=org.hibernate.dialect.HSQLDialect
[java] 23:18:44,937 DEBUG Configuration:1387 - current_session_context_class=thread
[java] 23:18:44,937 DEBUG Configuration:1387 - cache.provider_class=org.hibernate.cache.NoCacheProvider
[java] 23:18:44,937 DEBUG Configuration:1387 - show_sql=true
[java] 23:18:44,937 DEBUG Configuration:1387 - hbm2ddl.auto=create
[java] 23:18:44,937 DEBUG Configuration:1586 - null<-org.dom4j.tree.DefaultAttribute@dc6a77 [Attribute: name resource value "events/Event.hbm.xml"]
[java] 23:18:44,937 INFO Configuration:553 - Reading mappings from resource : events/Event.hbm.xml
[java] 23:18:44,953 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(1) A pseudo attribute name is expected.
[java] Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Could not parse mapping document from resource events/Event.hbm.xml
[java] Exception in thread "main" java.lang.ExceptionInInitializerError
[java] at util.HibernateUtil.<clinit>(Unknown Source)
[java] at events.EventManager.createAndStoreEvent(Unknown Source)
[java] at events.EventManager.main(Unknown Source)
[java] Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource events/Event.hbm.xml
[java] at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
[java] at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
[java] at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
[java] ... 3 more
[java] Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
[java] at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:508)
[java] at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
[java] ... 9 more
[java] Caused by: org.dom4j.DocumentException: Error on line 1 of document : A pseudo attribute name is expected. Nested exception: A pseudo attribute name is expected.
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:482)
[java] at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
[java] ... 10 more
Name and version of the database you are using:HSQLDB
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html