This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help mapping Hibernate with Netbeans  RSS feed

 
Avinashsharma Joshi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Chris Keene
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to solve this problem would be to create the project using WaveMaker, an open-source visual development platform for Java web apps. Create the project with WaveMaker, which produces a WAR file, then open the project in NetBeans and you'll have all the hibernate and spring config work done.

Hope that helps!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!