-->
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.  [ 1 post ] 
Author Message
 Post subject: Netbeans With Hibernate mapping Problem
PostPosted: Mon May 19, 2008 12:19 pm 
Newbie

Joined: Tue May 13, 2008 2:58 am
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I m using Hibernate version 3.2.2

My mapping Document is

---------------(A) HibernateUtil.java------------------

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

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory
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;
}

}

-----------------------(B) Person.java---------------

package hibernatetravelpojo;

public class Person implements java.io.Serializable {


public Person() {
}



private int personId;



public int getPersonId() {

return this.personId;
}


public void setPersonId(int personId) {

this.personId = personId;
}


private String name;


public String getName() {

return this.name;
}


public void setName(String name) {

this.name = name;
}

}

--------------------(C)Person.hbm.xml---------------
<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="hibernatetravelpojo.Person" table="person">


<!-- Primary Key -->
<id name="personId" column="PERSONID">
<generator class="increment"/>
</id>

<property name="name" column="NAME" type="java.lang.String"/>

</class>

</hibernate-mapping>

------------------------------(D) Hibernate.cfg.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>
<session-factory>
<!-- Data Source Name -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/Sandesh0107</property>
<property name="hibernate.connection.username">Avinash0107</property>
<property name="hibernate.connection.password">sharma</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.DerbyDialect</property>

<!-- Debug logging of SQL statements -->
<property name="show_sql">true</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Mapping Files -->
<mapping resource="hibernatetravelpojo/Person.hbm.xml"/>

</session-factory>
</hibernate-configuration>

-------------------------(E).java class

package hibernatetravelpojo;

import org.hibernate.Session;
import org.hibernate.Transaction;
import java.util.Set;
import org.hibernate.Query;
import org.hibernate.Session;
import java.util.List;
import java.util.Iterator;
import org.hibernate.Transaction;
import org.hibernate.*;
import org.hibernate.cfg.*;


public class NewClass1 {
public static void main(String[] args) {
// TODO code application logic here

Session session =HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Person per=new Person();
per.setPersonId(1);
per.setName("name");
session.save(per);
session.getTransaction().commit();


}

}


---------------------------My sql query-------------------------

Create table PERSON(PERSONID integer(10) Primary key Not Null,NAME varchar(20))
..........................................................................................................


Error-->


init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\sandesh\My Documents\NetBeansProjects\HibernateTravelPOJO\build\classes
compile-single:
run-single:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.MappingException: invalid configuration
Exception in thread "main" java.lang.ExceptionInInitializerError
at hibernatetravelpojo.HibernateUtil.<clinit>(HibernateUtil.java:27)
at hibernatetravelpojo.NewClass1.main(NewClass1.java:26)
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1487)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at hibernatetravelpojo.HibernateUtil.<clinit>(HibernateUtil.java:23)
... 1 more
Caused by: org.xml.sax.SAXParseException: Element type "value" must be declared.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1929)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:764)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2740)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.