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.  [ 2 posts ] 
Author Message
 Post subject: Exemple dans le tutoriel de hibernate
PostPosted: Wed Feb 14, 2007 1:55 pm 
Newbie

Joined: Wed Feb 14, 2007 1:46 pm
Posts: 3
Salut j'essaie de faire l'exemple du tutoriel de hibernate... Je réussie a le compiler avec ant. Mais lorsque je veux l'exécuter, je n'ai pas le résultat attendu car ca mindique que le parser n'arrive pas à parser les fichiers XML Voici mon code et voici le resultat. Merci!

Code

Classe Event
package events;

import java.util.*;

public class Event {
private Long id;

private String title;
private Date date;

public Event() {}

public Long getId() {
return id;
}

private void setId(Long id) {
this.id = id;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

}
/************************/
Classe EventManager
package events;

import org.hibernate.Session;
import java.util.Date;
import util.HibernateUtil;

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();
}

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();
}
}
/*****************************/
classe hibernateUtil

package util;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

}
/****************************/
le fichier Event.hbm.xml

<?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="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>
</hibernate-mapping>

/******************************/
le fichier hibernate.cfg.xml

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

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

/************************/
Et le message une fois exécuté

Buildfile: build.xml

clean:
[delete] Deleting directory C:\Documents and Settings\jon\workspace\test\bin
[mkdir] Created dir: C:\Documents and Settings\jon\workspace\test\bin

copy-resources:
[copy] Copying 3 files to C:\Documents and Settings\jon\workspace\test\bin
[copy] Copied 2 empty directories to 1 empty directory under C:\Documents and Settings\jon\workspace\test\bin

compile:
[javac] Compiling 3 source files to C:\Documents and Settings\jon\workspace\test\bin

run:
[java] 12:54:56,593 INFO Environment:509 - Hibernate 3.2.2
[java] 12:54:56,593 INFO Environment:542 - hibernate.properties not found
[java] 12:54:56,609 INFO Environment:676 - Bytecode provider name : cglib
[java] 12:54:56,609 INFO Environment:593 - using JDK 1.4 java.sql.Timestamp handling
[java] 12:54:56,671 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
[java] 12:54:56,671 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
[java] 12:54:56,937 DEBUG DTDEntityResolver:38 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
[java] 12:54:56,937 DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
[java] 12:54:56,937 DEBUG DTDEntityResolver:50 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
[java] 12:54:57,015 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(6) Document root element "hibernate-configuration", must match DOCTYPE root "hibernate-mapping".
[java] 12:54:57,015 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(6) Element type "hibernate-configuration" must be declared.
[java] 12:54:57,031 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(8) Element type "session-factory" must be declared.
[java] 12:54:57,046 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(11) The content of element type "property" must match "(meta*,(column|formula)*,type?)".
[java] 12:54:57,046 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(12) The content of element type "property" must match "(meta*,(column|formula)*,type?)".
[java] 12:54:57,046 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(13) The content of element type "property" must match "(meta*,(column|formula)*,type?)".
[java] Initial SessionFactory creation failed.org.hibernate.MappingException: invalid configuration
[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.MappingException: invalid configuration
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1487)
[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.xml.sax.SAXParseException: Document root element "hibernate-configuration", must match DOCTYPE root "hibernate-mapping".
[java] at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
[java] at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
[java] at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
[java] at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
[java] at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
[java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
[java] 12:54:57,062 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(17) The content of element type "property" must match "(meta*,(column|formula)*,type?)".
[java] 12:54:57,062 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(20) The content of element type "property" must match "(meta*,(column|formula)*,type?)".
[java] 12:54:57,062 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(23) The content of element type "property" must match "(meta*,(column|formula)*,type?)".
[java] 12:54:57,062 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(26) The content of element type "property" must match "(meta*,(column|formula)*,type?)".
[java] 12:54:57,062 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(29) The content of element type "property" must match "(meta*,(column|formula)*,type?)".
[java] 12:54:57,062 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(32) The content of element type "property" must match "(meta*,(column|formula)*,type?)".
[java] 12:54:57,078 ERROR XMLHelper:61 - Error parsing XML: /hibernate.cfg.xml(34) Element type "mapping" must be declared.
[java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
[java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:465)
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
[java] ... 5 more

BUILD SUCCESSFUL
Total time: 2 seconds


Merci bcp!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 3:47 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Le doctype de ton hibernate.cfg.xml n'est pas le bon

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.