Results 1 to 3 of 3
  1. #1
    KnightOfCode is offline Newbies
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default Hibernate - connect to database and run query.

    Sorry for lame question, but I`ve got a problem - can`t connect to MySQL dbs via hibernate with set up plugins in NetBeans IDE. I had created 2 files hibernate.cfg.xml and hibernate.hbm.xml then imported hibernate packeges and class compiled with error:

    May 22, 2011 9:04:03 AM org.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 3.2.5
    May 22, 2011 9:04:03 AM org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    May 22, 2011 9:04:03 AM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : cglib
    May 22, 2011 9:04:03 AM org.hibernate.cfg.Environment <clinit>
    INFO: using JDK 1.4 java.sql.Timestamp handling
    May 22, 2011 9:04:03 AM org.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    May 22, 2011 9:04:03 AM org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    May 22, 2011 9:04:04 AM org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource : hibernate.hbm.xml
    May 22, 2011 9:04:04 AM org.hibernate.util.XMLHelper$ErrorLogger error
    SEVERE: Error parsing XML: XML InputStream(9) The content of element type "class" is incomplete, it must match "(meta*,subselect?,cache?,synchronize*,comment?,tu plizer*,(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|ar ray|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
    Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource hibernate.hbm.xml
    at org.hibernate.cfg.Configuration.addResource(Config uration.java:569)
    at org.hibernate.cfg.Configuration.parseMappingElemen t(Configuration.java:1587)
    at org.hibernate.cfg.Configuration.parseSessionFactor y(Configuration.java:1555)
    at org.hibernate.cfg.Configuration.doConfigure(Config uration.java:1534)
    at org.hibernate.cfg.Configuration.doConfigure(Config uration.java:1508)
    at org.hibernate.cfg.Configuration.configure(Configur ation.java:1428)
    at org.hibernate.cfg.Configuration.configure(Configur ation.java:1414)
    at HiberTest.setUp(HiberTest.java:16)
    at HiberTest.main(HiberTest.java:22)
    Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
    at org.hibernate.cfg.Configuration.addInputStream(Con figuration.java:502)
    at org.hibernate.cfg.Configuration.addResource(Config uration.java:566)
    ... 8 more
    Caused by: org.xml.sax.SAXParseException: The content of element type "class" is incomplete, it must match "(meta*,subselect?,cache?,synchronize*,comment?,tu plizer*,(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|ar ray|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(ErrorHandlerWrap per.java:195)
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.error(ErrorHandlerWrapper.java:131)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:384)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:318)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTD Validator.handleEndElement(XMLDTDValidator.java:20 17)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTD Validator.emptyElement(XMLDTDValidator.java:791)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.scanStartElement(XMLNSDocumentScann erImpl.java:377)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDriver.next(XM LDocumentFragmentScannerImpl.java:2755)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.next(XMLNSDocumentScannerImpl.java: 140)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(XMLDocumentFragm entScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.Abstrac tSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserI mpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at org.dom4j.io.SAXReader.read(SAXReader.java:465)
    at org.hibernate.cfg.Configuration.addInputStream(Con figuration.java:499)
    ... 9 more
    Java Result: 1

    Here is the code:
    Java Code:
    import org.hibernate.*;
    import org.hibernate.cfg.*;
    import java.util.*;
    
    public class HiberTest {
    
      private static SessionFactory sessionFactory;
    
    protected static void setUp() throws Exception {
        // A SessionFactory is set up once for an application
        sessionFactory = new Configuration()
                .configure() // configures settings from hibernate.cfg.xml
                .buildSessionFactory();
    }
    
      public static void main(String[] args) throws Exception {
        setUp();
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Query q = session.createQuery("CREATE TABLE test(myInt int not null)");
            List resultList = q.list();
            System.out.println(resultList);
            session.getTransaction().commit();
            session.close();
      }
      
    }

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Hi. You have mistake in xml-mapping your model. Can you show your model and hibernate.hbm.xml. By the way. don't call mapping file like this, more understandable ti call it as like model file. for example model User.java and mapping file User.hbm.xml.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    "InvalidMappingException: Could not parse mapping document from resource hibernate.hbm.xml"
    Pretty much says it all.

Similar Threads

  1. hibernate distinct query
    By GlWy in forum JDBC
    Replies: 2
    Last Post: 04-07-2011, 06:59 PM
  2. Java - hibernate query with join
    By dergotic in forum Advanced Java
    Replies: 0
    Last Post: 09-29-2010, 09:02 PM
  3. Hibernate Join Query - Should be easy
    By ajt111 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 10-29-2009, 05:48 PM
  4. Help query with hibernate
    By wonderbiker in forum JDBC
    Replies: 0
    Last Post: 04-14-2009, 11:12 AM
  5. Hibernate sql query
    By taicode in forum JDBC
    Replies: 0
    Last Post: 03-25-2008, 04:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •