-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Doesnt work (HSQL)
PostPosted: Wed May 17, 2006 12:01 pm 
Newbie

Joined: Wed May 17, 2006 11:52 am
Posts: 5
It is the first time I user hibernate. The information about the errors is below.

If I only use the "class"-declaration of sa.bo.UserDAO in the XML file no errors occur but I don't see any errors in the sa.bo.TrainingDAO.


Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="sa.bo.UserDAO" table="saTaUser">
      <id name="Id" >
            <column name="sUserId" not-null="true"/>
        </id>
       
        <property name="Vorname">
            <column name="sVorname" length="60" not-null="false" />
        </property>
       
        <property name="Nachname">
           <column name="sNachname" length="60" not-null="false" />
        </property>
       
        <property name="Plz">
           <column name="sPlz" length="30" not-null="false" />
        </property>
       
        <property name="Ort">
           <column name="sOrt" length="60" not-null="false" />
        </property>
       
        <property name="Strasse">
           <column name="sStrasse" length="60" not-null="false" />
        </property>       
    </class>
   
    <class name="sa.bo.TrainingDAO" table="saTaTraining">
        <property name="EinheitStart">
            <column name="tEinheitStart" not-null="false" />
        </property>
       
        <property name="EinheitEnde">
           <column name="tEinheitEnde" not-null="false" />
        </property>
       
        <property name="Beschreibung">
           <column name="sBeschreibung" length="240" not-null="false" />
        </property>
       
        <property name="AnzahlKm">
           <column name="nAnzahlKm" not-null="false" />
        </property>
       
        <property name="UserId">
           <column name="sUserId" length="10" not-null="false" />
        </property>       
    </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
        Session oSession = HibernateUtil.currentSession();
        oSession.beginTransaction();
       
        oNewUser.setId(sId);
        oNewUser.setVorname(sVorname);
        oNewUser.setNachname(sNachname);
        oNewUser.setPlz(sPlz);
        oNewUser.setOrt(sOrt);
        oNewUser.setStrasse(sStrasse);
       
        oSession.save(oNewUser);
        oSession.getTransaction().commit();
        HibernateUtil.closeSession();

Full stack trace of any exception that occurs:
Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.ExceptionInInitializerError
   at util.HibernateUtil.<clinit>(HibernateUtil.java:39)
   at sa.admin.Userverwaltung.insert(Userverwaltung.java:170)
   at sa.admin.Userverwaltung.main(Userverwaltung.java:49)
Caused by: org.hibernate.MappingException: Could not read mappings from resource: User.hbm.xml
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
   at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
   at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
   at util.HibernateUtil.<clinit>(HibernateUtil.java:34)
   ... 2 more
Caused by: org.hibernate.MappingException: invalid mapping
   at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:425)
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
   ... 9 more
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*)".
   at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
   at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
   at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
   at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
   at org.dom4j.io.SAXReader.read(SAXReader.java:465)
   at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:422)
   ... 10 more



Name and version of the database you are using:
HSQL


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 12:09 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
Your sa.bo.TrainingDAO class declaration has no key defined. It is compulsory to declare a key for each class. Your other class declaration is working because you have declared a key using the <id/> tag.

Hope that helps,
Cheers,
Rich.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 12:09 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
One problem could be that you have wrong hibernate.jar file in your classpath. Also I have changed the DOCTYPE element to get DTD fomr PUBLIC and not SYSTEM if JAR file is wrong one.


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">


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 1:43 pm 
Newbie

Joined: Wed May 17, 2006 11:52 am
Posts: 5
Quote:
Your sa.bo.TrainingDAO class declaration has no key defined. It is compulsory to declare a key for each class. Your other class declaration is working because you have declared a key using the <id/> tag.

That helped. Thank you very much


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.