Hibernate hibernate.cfg.xml

stephanie

Aktives Mitglied
Hallo,

ich will mein erstes Hibernate Projekt konfiguriern, ich habe immer gleiche fehler. Ich habe sogar im youtube ein tutorial geguckt und das gleiche gemacht. troztdem konnte nicht es schaffen.

das fehler wie folgendes:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See SLF4J Error Codes for further details.
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: META-INF/classes/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
at org.java.test.UserTest.main(UserTest.java:19)
Caused by: org.dom4j.DocumentException: Error on line 2 of document : Content ist nicht zulässig in Prolog. Nested exception: Content ist nicht zulässig in Prolog.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
... 2 more
wenn jemand behilflich sein könnte würde sehr dankbar
 
Zuletzt bearbeitet von einem Moderator:
Hibernate ist kein Anfängerthema, Doku lesen ist Pflicht.

Ansonsten:
Du hast wohl Kommentare am Anfang deiner hibernate.cfg.xml.

*verschoben*
 
.

Ansonsten:
Du hast wohl Kommentare am Anfang deiner hibernate.cfg.xml.

ich habe nicht verstanden, was du meinst?

und warum hibernate nicht anfänger thema?? ich kann java programmieren und will jetzt hibernate beherrschen
 
Hibernate ist kompliziert,
wie man sieht sind z.B. ein bis zehn Stufen darunter Themengebiete wie
- XML kennen
- Fehlermeldungen verstehen (es gibt Probleme mit hibernate.cfg.xml)
- eigene Denkfähigkeiten wie dann diese Datei zumindest hier zu posten (sorry 😉 )

die Aufteilung der Areas ist nach Themen, nicht nach Wissenstand,
wie sieht denn jetzt die hibernate.cfg.xml-Datei ganz genau aus?
 
ganz ist es so
[XML]
- <!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
~ indicated by the @author tags or express copyright attribution
~ statements applied by the authors. All third-party contributions are
~ distributed under license by Red Hat Inc.
~
~ This copyrighted material is made available to anyone wishing to use, modify,
~ copy, or redistribute it subject to the terms and conditions of the GNU
~ Lesser General Public License, as published by the Free Software Foundation.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
~ for more details.
~
~ You should have received a copy of the GNU Lesser General Public License
~ along with this distribution; if not, write to:
~ Free Software Foundation, Inc.
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA


-->
<?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.postgresql.Driver</property>
<property name="connection.url">jdbc😛ostgresql://localhost:5432/DB</property>
<property name="connection.username">postgres</property>
<property name="connection.password" >123456789</property>
- <!-- JDBC connection pool (use the built-in)
-->
<property name="connection.pool_size">1</property>
- <!-- SQL dialect
-->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</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 class="org/java/user/USER" />
</session-factory>
</hibernate-configuration>[/XML]
 
dann versuche stattdessen

[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.postgresql.Driver</property>
<property name="connection.url">jdbc😛ostgresql://localhost:5432/DB</property>
<property name="connection.username">postgres</property>
<property name="connection.password" >123456789</property>
<!-- JDBC connection pool (use the built-in)
-->
<property name="connection.pool_size">1</property>
<!-- SQL dialect
-->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</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 class="org/java/user/USER" />
</session-factory>
</hibernate-configuration>[/XML]
bzw. der Kommentar am Anfang mag wieder rein, das Problem sind wohl die Leerzeichen + Bindestriche am Anfang jeder Zeile (je zwei)
 
Ich habe versucht wie du mir vorgeschlagen hast, dann habe ich folgendes:


SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See SLF4J Error Codes for further details.
Exception in thread "main" org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2241)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
at org.java.test.UserTest.main(UserTest.java:19)
Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 26; Dokument-Root-Element "hibernate-configuration"muss mit DOCTYPE-Root "hibernate-mapping" übereinstimmen.
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.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(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 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
... 2 more
 
die Zeilen zu "<!DOCTYPE hibernate-mapping PUBLIC" habe ich bei mir nur bei Mapping-XML-Files pro einzelner Klasse stehen,
in der Configuration sollte es bestimmt mit
[xml]
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
[/xml]
anfangen statt bei dir
[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>
[/xml]
wobei ich das auch nur irgendwo richtig kopiert habe (deine Quelle fragwürdig?),
mehr brauch das kaum zu interessieren,
[c]encoding="utf-8"[/c] kannst du evtl. weglassen, schadet aber vielleicht auch nicht
 
da du so eine Schnellposterin bist und nun schon glatte 7 Min. keine Antwort kam, zur Sicherheit noch:
siehe auch meine Antwort zwischendurch
 
Sollst sie auch nicht nur ansehen, sondern lesen, da steht alles drinnen 😉

Es gibt keine bessere Hibernate Doku als die Hibernate Doku, die meisten anderen Tutorials sind falsch, reine Zeitverschwendung.

Das geht übrigens vielen so dass sie irgendwo von irgendwem ein Hibernate Tutorial/Video gesehen haben und dann mit den Problemen hierher kommen, Antwort:
Entweder Doku lesen oder an den Author des Tutorials/Videos wenden.

Jeder Dödel mein heute leider er müsste ein Hibernate Tutorial erstellen..
 
maki habe ich schon ein buch gelesen und als ich dieses project angefangen habe, habe ich die videos gefolgt. sondern habe ich nicht richtig aufgepasst🙂) danke schön troztdem. ich sorge auf deinen Vorschlag 😉

und slaterb, ja richtig habe ich deine antwort später gesehen und wollte gleich machen. schon gut🙂
 

Zurück
Oben