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: element of resource file
PostPosted: Thu Jul 08, 2010 3:30 am 
Newbie

Joined: Thu Jul 08, 2010 3:19 am
Posts: 1
Hi,
I developed an application which is successfully inserting name and id(primary key) in a TESTTABLE .Then i developed an application which should insert only name(single column) in NAMETABLE,but it is showing an error


log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Error reading resource: test.hbm.xml
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.NameExample.main(NameExample.java:33)


Is it mandatory to have <id> in resource file?

My Files are

1)package roseindia.tutorial.hibernate;

public class NameTable {
private String name;
public String getName() {
return name;
}
public void setName(String string) {
name = string;
}
}



2)
package roseindia.tutorial.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class NameExample {
public static void main(String[] args) {
Session session = null;
try {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
System.out.println("Inserting Record");
Transaction tx = session.beginTransaction();
NameTable contact = new NameTable();
contact.setName("Deepak");
session.save(contact);
tx.commit();
System.out.println("Done");
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
session.flush();
session.close();
}
}
}



3)
<?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="roseindia.tutorial.hibernate.TestTable" table="TEST">
<id name="id" type="int" column="ID" >
<generator class="assigned"/>
</id>
<property name="FirstName">
<column name="NAME" />
</property>
</class>
<class name="roseindia.tutorial.hibernate.NameTable" table="NAMETABLE">

<property name="name">
<column name="NAME" />
</property>
</class>
</hibernate-mapping>



4)
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//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:3309/hibernatetutorial</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">admin</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="test.hbm.xml"/>
</session-factory>
</hibernate-configuration>


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.