You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by beyaNet Consultancy <be...@ntlworld.com> on 2004/01/21 21:29:17 UTC

Exception in Hibernate:problem parsing configuration/test/hibernate.cfg.xml

Hi,
I am getting the above message when I try and run hibernate from 
cocoon. Can anyone tell me what I am doing incorrectly?

1. class snippet:

public void add(){
         try {
             Configuration cfg = new Configuration()
             .configure ("/test/hibernate.cfg.xml");
             SessionFactory sf = cfg.buildSessionFactory();
             Session session = sf.openSession();
			Transaction transaction = session.beginTransaction();
			
			User usr = new User();
			usr.setID("143");
			usr.setUserName("x");
			usr.setPassword("x");
			usr.setEmailAddress("test@hotmail.com");
			usr.setLastLogon(newDate);
			
             session.save(usr);
			session.flush();
			transaction.commit();
		
             session.close();
             session = null;

             sf.close();
             sf = null;

             cfg = null;
			
         }
         catch ( Exception e) {
             state = "Exception in Hibernate: " + e.getMessage();
         }

2. hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd";>


<hibernate-configuration>

     <session-factory>
         <property 
name="connection.driver_class">org.postgresql.Driver</property>
		<property 
name="connection.url">jdbc:postgresql://localhost:5432/test</property>
		<property name="connection.username">x</property>
		<property name="connection.password">x</property>
		<property name="show_sql">false</property>
         <property name="use_outer_join">true</property>
         <property 
name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>

         <mapping resource="User2.hbm.xml"/>


     </session-factory>

</hibernate-configuration>

3. Users2.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.1//EN"
    "http://hibernate.sourceforge.net/hibernate-2.1.dtd">

<hibernate-mapping>
	<class name="test.User" table="users">
		<id name="ID" type="string" unsaved-value="null">
			<column name="LogonID" sql-type="char(32)" not-null="true"/>
             <generator class="uuid.hex"/>
		</id>
		
		<property name="userName" column="Name" type="string"/>
		<property name="password" column="Password" type="string"/>
		<property name="emailAddress" column="EmailAddress" type="string"/>
		<property name="lastLogon" column="Lastlogon" type="date"/>
	</class>
</hibernate-mapping>

Andrew