-->
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: Error in Running my Program.............
PostPosted: Wed Nov 19, 2008 12:53 am 
Newbie

Joined: Wed Nov 19, 2008 12:47 am
Posts: 1
I am new to hibernate.......I have some errors in while Running my program using Ecllipse..

/****Table/****

create table student(sno number(20),sname varchar(20),mobile number(10),email varchar(20));

Table created.

//****POJO class***///


import java.io.Serializable;

public class Student implements Serializable {
private int sno;
private String sname;
private long mobile;
private String email;

public Student() {
}

public int getSno() {
return sno;
}

public void setSno(int sno) {
this.sno = sno;
}

public String getSname() {
return sname;
}

public void setSname(String sname) {
this.sname = sname;
}

public long getMobile() {
return mobile;
}

public void setMobile(long mobile) {
this.mobile = mobile;
}

public String getEmail() {
return email;
}

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

}

/**ClientStudent.java***//

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

class ClientStudent {

public static void main(String[] args) {


try{
Configuration cfg= new Configuration();
cfg.configure("/hibernate.cfg.xml");
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
student Sto = new student();
Sto.setSno(1);
Sto.setSname("saichand");
Sto.setMobile(412171);
Sto.setEmail("saichand_varanasi@yahoo.com");
session.save(Sto);
tx.commit();
session.close();

}catch(HibernateException ex)
{
ex.printStackTrace();
}
}

}
CONTd..........

/****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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="myeclipse.connection.profile">
OracleEx
</property>
<property name="connection.driver_class">
sun.jdbc.odbc.JdbcOdbcDriver
</property>
<property name="connection.url">jdbc:odbc:dfi</property>
<property name="connection.username">system</property>
<property name="connection.password">tiger</property>
<property name="dialect">
org.hibernate.dialect.DB2400Dialect
</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.connection.autocommit">
false
</property>
<mapping resource="student.hdm.xml" />
</session-factory>
</hibernate-configuration>

//**student.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="student" table="student">
<id name="sno" column="sno" type="integer">
<generator class="assigned"/>
</id>
<property name="sname" column="sname" type="string"/>
<property name="mobile" column="mobile" type="string"/>
</class>
</hibernate-mapping>
These are the two .xml files......







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.ClassCastException: java.lang.Integer
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:168)
at org.hibernate.pretty.Printer.toString(Printer.java:53)
at org.hibernate.pretty.Printer.toString(Printer.java:90)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:97)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at ClientStudent.main(ClientStudent.java:21)


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.