Hello,
I am a newbie and hope someone can help me with this. I am trying to learn Hibernate by using the tutorial, but I got stuck here. I am getting parsing error when Ant tries to compile my project. Please see all data below. Thanks in advance!
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:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);
session.save(theEvent);
session.getTransaction().commit();
Build.xmlCode:
<project name="hibernate-tutorial" default="run">
<property name="sourcedir" value="${basedir}/src"/>
<property name="targetdir" value="${basedir}/bin"/>
<property name="librarydir" value="${basedir}/lib"/>
<path id="libraries">
<fileset dir="${librarydir}">
<include name="*.jar"/>
<include name="bytecode/*.jar"/>
<include name="optional/*.jar"/>
<include name="required/*.jar"/>
</fileset>
</path>
<target name="clean">
<delete dir="${targetdir}"/>
<mkdir dir="${targetdir}"/>
</target>
<target name="compile" depends="clean, copy-resources">
<javac srcdir="${sourcedir}"
destdir="${targetdir}"
classpathref="libraries"/>
</target>
<target name="copy-resources">
<copy todir="${targetdir}">
<fileset dir="${sourcedir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="run" depends="compile">
<java fork="true" classname="events.EventManager" classpathref="libraries">
<classpath path="${targetdir}"/>
<arg value="${action}"/>
</java>
</target>
</project>
Full stack trace of any exception that occurs:
[java] 2009-feb-20 10:50:55 org.hibernate.cfg.Environment <clinit>
[java] INFO: Hibernate 3.3.1.GA
[java] 2009-feb-20 10:50:56 org.hibernate.cfg.Environment <clinit>
[java] INFO: loaded properties from resource hibernate.properties: {hiberna
te.connection.driver_class=org.hsqldb.jdbcDriver, hibernate.cache.provider_class
=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibern
ate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.jdbc.use_streams_for_bi
nary=true, hibernate.format_sql=true, hibernate.query.substitutions=yes 'Y', no
'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=sa, hiber
nate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:hsqldb:./
build/db/hsqldb/hibernate, hibernate.bytecode.use_reflection_optimizer=false, hi
bernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibe
rnate.connection.pool_size=1}
[java] 2009-feb-20 10:50:56 org.hibernate.cfg.Environment <clinit>
[java] INFO: using java.io streams to persist binary types
[java] 2009-feb-20 10:50:56 org.hibernate.cfg.Environment buildBytecodeProv
ider
[java] INFO: Bytecode provider name : javassist
[java] 2009-feb-20 10:50:56 org.hibernate.cfg.Environment <clinit>
[java] INFO: using JDK 1.4 java.sql.Timestamp handling
[java] 2009-feb-20 10:50:56 org.hibernate.cfg.Configuration configure
[java] INFO: configuring from resource: /hibernate.cfg.xml
[java] 2009-feb-20 10:50:56 org.hibernate.cfg.Configuration getConfiguratio
nInputStream
[java] INFO: Configuration resource: /hibernate.cfg.xml
[java] 2009-feb-20 10:50:56 org.hibernate.util.XMLHelper$ErrorLogger error
[java] ALLVARLIG: Error parsing XML: /hibernate.cfg.xml(2) Content is not a
llowed in prolog.
[java] Initial SessionFactory creation failed.org.hibernate.HibernateExcept
ion: Could not parse configuration: /hibernate.cfg.xml
[java] Exception in thread "Main Thread" java.lang.ExceptionInInitializerEr
ror
[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.HibernateException: Could not parse configu
ration: /hibernate.cfg.xml
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.jav
a:1528)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:
1462)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:
1448)
[java] ... 3 more
[java] Caused by: org.dom4j.DocumentException: Error on line 2 of document
: Content is not allowed in prolog. Nested exception: Content is not allowed in
prolog.
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:482)
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.jav
a:1518)
[java] ... 5 more
[java] Java Result: 1
Name and version of the database you are using:
HSQLDB 1.8.0.10
Best Regards,
Niklas