-->
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.  [ 3 posts ] 
Author Message
 Post subject: Newbie: parse fail in persistence.xml
PostPosted: Fri Dec 29, 2006 7:52 pm 
Newbie

Joined: Fri Mar 04, 2005 7:10 am
Posts: 12
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.


Top
 Profile  
 
 Post subject: my eclipse editor put hyphens in the file!
PostPosted: Fri Dec 29, 2006 8:04 pm 
Newbie

Joined: Fri Mar 04, 2005 7:10 am
Posts: 12
hah, spotted something

looked again at the persistence file and it has hyphens in the body - dont know where those came from - i thought it was a visual editor marker showing the started of an indented section but it wasnt - it was real text in the file.

Fixed that and it nearly works

I now get

Code:


java.lang.UnsupportedOperationException: The user must supply a JDBC connection
   at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
   at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
   at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
   at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
   at PersistenceManager.<clinit>(PersistenceManager.java:17)
   at App.main(App.java:13)


why do i need to provide a jdbc connection and where do i do it? Is this because i am in j2se mode and i'm managing the database at app level.

in the persistence.xml i tell it the properties for the mysql DB. Why do I have to hand crank a connection. How would i pass it in as xml config?

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>



[/code]


Top
 Profile  
 
 Post subject: eurika - fixed myself !
PostPosted: Fri Dec 29, 2006 9:39 pm 
Newbie

Joined: Fri Mar 04, 2005 7:10 am
Posts: 12
if any one is reading the trail - I fixed myself i think.

I spotted that i hadnt prefixed hibernate. to my connection seeting sin the properties (I think i copied this from some sample pdf file and must have missed it.

secondly i had missed the extra colon in the jdbc:mysql connect string and was no way i was going to get a connection.

fixed both of these and bingo - my silly little app appears to work

and now to dig around abit on the real application


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