Can anyone help - getting a parse error on persistence xml that is stopping me at the first hurdle
I am running jboss eclipse v2 beta 2, and compiler is set to java 6.
unpacked all the hibernate, annotations and entity manager zips and included all the jars from the /lib and the main jar files into my class path
using mysql as the test database. I'm trying to do this as simple as possible in a j2se test mode at present before we stretch out for ejb3 containers etc.
i've created a simple app to test the entity manager/annotations and got stuck.
Hibernate version:
hibernate 3.2.1 GA all.
my project structure is
Code:
app
src
(def package)
app.java (main)
node.java (persistant annotated class)
persistentManager.java (returns entityManager from bootstrap load)
META-INF
persistance.xml
log4j.properties
my persistence.xml is as follows
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
- <persistence-unit name="manager" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
- <properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="show_sql" value="true"/>
<property name="connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="connection.url" value="jdbc:mysql//localhost/app"/>
<property name="connection.username" value="will"/>
<property name="connection.password" value=""/>
</properties>
</persistence-unit>
</persistence>
my persistnant manager class is follows
Code:
import javax.persistence.*;
public class PersistenceManager
{
// declare static factory
private static final EntityManagerFactory emf;
//initiatlise the factory at class loader time
static
{
System.out.println ("static method getting entity manager factory\n");
try {
// Create the EntityManagerFactory from META-INF/persistence.xml
emf = Persistence.createEntityManagerFactory("manager");
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial EntityManagerFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public EntityManager getEntityManager()
{
EntityManager em =emf.createEntityManager();
return em;
}
}
I have logging (default ) turned on.
my main app does the following
Code:
import javax.persistence.*;
public class App
{
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
PersistenceManager pm = new PersistenceManager ();
EntityManager em = pm.getEntityManager();
Node node = new Node ("my node");
em.persist(node);
System.out.println ("saved node called" + node.getNodeName());
}
}
what i get is an error from the parser at run time that I cant figure out
Quote:
static method getting entity manager factory
23:10:26,481 INFO Version:15 - Hibernate EntityManager 3.2.1.GA
23:10:26,501 INFO Version:15 - Hibernate Annotations 3.2.1.GA
23:10:26,511 INFO Environment:500 - Hibernate 3.2.1
23:10:26,521 INFO Environment:533 - hibernate.properties not found
23:10:26,521 INFO Environment:667 - Bytecode provider name : cglib
23:10:26,521 INFO Environment:584 - using JDK 1.4 java.sql.Timestamp handling
23:10:27,062 ERROR PersistenceXmlLoader:237 - Error parsing XML: XML InputStream(18) cvc-complex-type.2.3: Element 'persistence-unit' cannot have character [children], because the type's content type is element-only.
23:10:27,072 ERROR PersistenceXmlLoader:237 - Error parsing XML: XML InputStream(19) cvc-complex-type.2.3: Element 'persistence' cannot have character [children], because the type's content type is element-only.
Initial EntityManagerFactory creation failed.javax.persistence.PersistenceException: invalid persistence.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at PersistenceManager.<clinit>(PersistenceManager.java:21)
at App.main(App.java:13)
Caused by: javax.persistence.PersistenceException: invalid persistence.xml
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:72)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:79)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:212)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at PersistenceManager.<clinit>(PersistenceManager.java:17)
... 1 more
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.3: Element 'persistence-unit' cannot have character [children], because the type's content type is element-only.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.elementLocallyValidType(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.processElementContent(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleEndElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:70)
... 7 more
i've looked at the PDF file and my persistenace.xml looks okay (i think). I looked at the .xsd in the entity manager dir and it says persistence and persistence unit elements do have children - so why do i get the the
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.3: Element 'persistence-unit' cannot have character [children], because the type's content type is element-only.
error in the parse? - i cant figure out what i'm doing wrong - can any one help spot my error.