-->
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.  [ 4 posts ] 
Author Message
 Post subject: pls help me: could not parse mapping document from resource
PostPosted: Wed Mar 07, 2007 2:56 am 
Newbie

Joined: Sun Mar 04, 2007 9:41 pm
Posts: 15
Location: SIN
Hi

I am using jdk 6.0, eclipse 3.2 and hibernate 3.
When i am running client program it gives me this error please help me

Could not parse mapping document from resource user.hbm.xml
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NullPointerException
at UserClient.main(UserClient.java:39)

This is my hibernate.cfg.xml file:

<?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>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/pos1</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="user.hbm.xml"/>

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


This is my user.hbm.xml file:

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

<hibernate-mapping>
<class name="User" table="user">
<id column="user_id" name="userid" type="java.lang.String">
// <generator class="increment"/>
</id>

<property column="user_name"
length="100"
name="userName"
type="java.lang.String"/>
<property column="user_password"
length="50"
name="userPassword"
type="java.lang.String"/>
<property column="user_first_name"
length="100"
name="userFirstName"
type="java.lang.String"/>
<property column="user_last_name
length="100"
name="userLastName"
type="java.lang.String"/>
<property column="user_address"
length="255"
name="userAddress"
type="java.lang.String"/>
<property column="city"
length="100"
name="city"
type="java.lang.String"/>
<property column="zip_code"
length="100"
name="zipCode"
type="java.lang.String"/>
<property column="contact_no"
length="15"
name="contactNo"
type="java.lang.String"/>
<property column="user_email"
length="100"
name="userEmail"
type="java.lang.String"/>
<property column="user_creation_date"
name="userCreationDate"
type="java.util.Date"/>
<property column="user_role"
length="25"
name="userRole"
type="java.lang.String"/>
</class>
</hibernate-mapping>



This is client program:

import java.util.Date;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class UserClient {
public static void main(String[] args) {
Session session = null;

try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
User user = new User();
user.setUserId("u1");
user.setUserName("abc");
user.setUserFirstName("xyz");
user.setUserLastName("ag");
user.setUserAddress("te");
user.setCity("S");
user.setZipCode("520");
user.setContactNo("839423");
user.setUserEmail("jiewo@df");
user.setUserCreationDate(new Date());
user.setUserRole("Manager");

session.save(user);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());

}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();


}

}
}


Last edited by noem on Wed Mar 07, 2007 4:12 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 07, 2007 3:24 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
1. Please use the code/quote/etc. tags when posting in the forum. It'll make your posts more readable.

Well, where is located your User class? (Fully Qualified Name).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 07, 2007 3:43 am 
Newbie

Joined: Sun Mar 04, 2007 9:41 pm
Posts: 15
Location: SIN
User class

import java.util.Date;

public class User {

/**public void setName(String name) {
/** identifier field */

private String userId;
/** persistent field */

private String userName;
/** persistent field */

private String userPassword;
/** persistent field */

private String userFirstName;
/** persistent field */

private String userLastName;
/** persistent field */

private String userAddress;
/** persistent field */

private String city;
/** persistent field */

private String zipCode;
/** persistent field */

private String contactNo;
/** persistent field */

private String userEmail;
/** persistent field */

private Date userCreationDate;
/** persistent field */

private String userRole;
/** persistent field */

public User(String userId, String userName, String userPassword, String userFirstName,
String userLastName, String userAddress, String city, String zipCode,
String contactNo, String userEmail, Date userCreationDate, String userRole){

this.userId = userId;
this.userName = userName;
this.userPassword = userPassword;
this.userFirstName = userFirstName;
this.userLastName = userLastName;
this.userAddress = userAddress;
this.city = city;
this.zipCode = zipCode;
this.contactNo = contactNo;
this.userEmail = userEmail;
this.userCreationDate = userCreationDate;
this.userRole = userRole;

}

/** default constructor */
public User() {
}

public String getUserId() {
return this.userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public String getUserName() {
return this.userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getUserPassword() {
return this.userPassword;
}

public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}

public String getUserFirstName() {
return this.userFirstName;
}

public void setUserFirstName(String userFirstName) {
this.userFirstName = userFirstName;
}

public String getUserLastName() {
return this.userLastName;
}

public void setUserLastName(String userLastName) {
this.userLastName = userLastName;
}

public String getUserAddress(){
return this.userAddress;
}

public void setUserAddress(String userAddress){
this.userAddress = userAddress;
}

public String getCity(){
return this.city;
}

public void setCity(String city){
this.city = city;
}

public String getZipCode(){
return this.zipCode;
}

public void setZipCode(String zipCode){
this.zipCode = zipCode;
}

public String getContactNo(){
return this.contactNo;
}

public void setContactNo(String contactNo){
this.contactNo = contactNo;
}

public String getUserEmail() {
return this.userEmail;
}

public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}

public Date getUserCreationDate() {
return this.userCreationDate;
}

public void setUserCreationDate(Date userCreationDate) {
this.userCreationDate = userCreationDate;
}

public String getUserRole(){
return this.userRole;
}

public void setUserRole(String userRole){
this.userRole = userRole;
}
}

// End of class /**


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 23, 2007 9:46 am 
Newbie

Joined: Mon Jul 23, 2007 9:36 am
Posts: 2
did u get reply to this topic....
i am also getting the same problem...plz help me out


noem wrote:
User class

import java.util.Date;

public class User {

/**public void setName(String name) {
/** identifier field */

private String userId;
/** persistent field */

private String userName;
/** persistent field */

private String userPassword;
/** persistent field */

private String userFirstName;
/** persistent field */

private String userLastName;
/** persistent field */

private String userAddress;
/** persistent field */

private String city;
/** persistent field */

private String zipCode;
/** persistent field */

private String contactNo;
/** persistent field */

private String userEmail;
/** persistent field */

private Date userCreationDate;
/** persistent field */

private String userRole;
/** persistent field */

public User(String userId, String userName, String userPassword, String userFirstName,
String userLastName, String userAddress, String city, String zipCode,
String contactNo, String userEmail, Date userCreationDate, String userRole){

this.userId = userId;
this.userName = userName;
this.userPassword = userPassword;
this.userFirstName = userFirstName;
this.userLastName = userLastName;
this.userAddress = userAddress;
this.city = city;
this.zipCode = zipCode;
this.contactNo = contactNo;
this.userEmail = userEmail;
this.userCreationDate = userCreationDate;
this.userRole = userRole;

}

/** default constructor */
public User() {
}

public String getUserId() {
return this.userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public String getUserName() {
return this.userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getUserPassword() {
return this.userPassword;
}

public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}

public String getUserFirstName() {
return this.userFirstName;
}

public void setUserFirstName(String userFirstName) {
this.userFirstName = userFirstName;
}

public String getUserLastName() {
return this.userLastName;
}

public void setUserLastName(String userLastName) {
this.userLastName = userLastName;
}

public String getUserAddress(){
return this.userAddress;
}

public void setUserAddress(String userAddress){
this.userAddress = userAddress;
}

public String getCity(){
return this.city;
}

public void setCity(String city){
this.city = city;
}

public String getZipCode(){
return this.zipCode;
}

public void setZipCode(String zipCode){
this.zipCode = zipCode;
}

public String getContactNo(){
return this.contactNo;
}

public void setContactNo(String contactNo){
this.contactNo = contactNo;
}

public String getUserEmail() {
return this.userEmail;
}

public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}

public Date getUserCreationDate() {
return this.userCreationDate;
}

public void setUserCreationDate(Date userCreationDate) {
this.userCreationDate = userCreationDate;
}

public String getUserRole(){
return this.userRole;
}

public void setUserRole(String userRole){
this.userRole = userRole;
}
}

// End of class /**


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