-->
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.  [ 3 posts ] 
Author Message
 Post subject: hi can any one find out the mistake in this...
PostPosted: Sat Sep 27, 2008 2:39 pm 
Newbie

Joined: Sat Sep 27, 2008 2:31 pm
Posts: 1
Location: US
Contact.java
public class Contact
{
private String firstName;
private String lastName;
private String email;
private long id;

public void setFirstName(String firstName)
{
this.firstName=firstName;
}
public String getFirstName()
{
return firstName;
}

public void setLastName(String lastName)
{
this.lastName=lastName;
}
public String getLastName()
{
return lastName;
}

public void setEmail(String email)
{
this.email=email;
}
public String getEmail()
{
return email;
}

public void setId(long id)
{
this.id=id;
}
public long getId()
{
return id;
}
}

hibernat-cfg.xml

<?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">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ORCL</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.password">tiger</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>

contact.hbm.xml

<?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="Contact" table="CONTACT">
<id name="id" type="long" column="ID">
<generator class="assigned"/>
</id>

<property name="firstName">
<column name="FIRSTNAME"/>
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>

FirstExample.java

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

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

try
{
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();

session=sessionFactory.openSession();


System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(3);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak@gmail.com");

session.save(contact);
System.out.println("Done");
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
finally
{
session.flush();
session.close();
}
}
}

this is my program..

my jdk is 1.5
jdbc is oracle 10g

in class path i include these

set CLASSPATH=C:\hibernate-3.0alpha\hibernate3.jar;C:\hibernate-3.0alpha\lib\dom4j-1.4.jar;C:\hibernate-3.0alpha\lib\cglib-full-2.0.2.jar;C:\hibernate-3.0alpha\lib\hibernate-tools.jar;C:\hibernate-3.0alpha\lib\commons-logging-1.0.4.jar;C:\hibernate-3.0alpha\lib\commons-collections-2.1.1.jar;%CLASSPATH%

and in env variable i included classes12.jar

it is compiling fine

all these four files i put it in one folder and i compiled like this

first set the class path
after that i compiled
javac *.java

after that i run the program
java FirstExample

it is showing error like this


Sep 27, 2008 11:05:29 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0 alpha
Sep 27, 2008 11:05:29 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Sep 27, 2008 11:05:29 AM org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Sep 27, 2008 11:05:29 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Sep 27, 2008 11:05:29 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Sep 27, 2008 11:05:29 AM org.hibernate.cfg.Configuration getConfigurationInput
ream
INFO: Configuration resource: /hibernate.cfg.xml
Sep 27, 2008 11:05:29 AM org.hibernate.cfg.Configuration getConfigurationInput
ream
WARNING: /hibernate.cfg.xml not found
/hibernate.cfg.xml not found
Exception in thread "main" java.lang.NullPointerException
at FirstExample.main(FirstExample.java:34)


is it the correct way to compile the program

or please suggest me.. iam new to hibernate...

_________________
Thanks
Subhash Kadiyala
kadiyalasubhash@gmail.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 27, 2008 4:04 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Hibernate is looking for your .hbm.xml at the default place (right below the /classes directory), but can't find it.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 28, 2008 9:54 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
gonzao_diaz wrote:
Hibernate is looking for your .hbm.xml at the default place (right below the /classes directory), but can't find it.


After putting the hibernate.cfg.xml, don't forget to open the transaction before save the object and commit it


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