please help me i am new with hibernat ______________________________________ when i am executing my program i am getting following exception _____________________________________________________
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at HibernateBasicTestCase.createEmployee(HibernateBasicTestCase.java:20) at HibernateBasicTestCase.main(HibernateBasicTestCase.java:108)Caused by: java.sql.BatchUpdateException: ORA-12899: value too large for column "SYSTEM"."EMP"."HIREDATE" (actual: 31, maximum: 10) at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10657) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195) ... 9 more Exception is creating an Employee
____________________________________________________________ import org.hibernate.cfg.*; import org.hibernate.*; import org.apache.log4j.Logger; import org.apache.log4j.Level; import java.util.Date; import com.santosh.hibernate.Employee;
public class HibernateBasicTestCase {
private SessionFactory factory; public void createEmployee(Employee emp){ Session session=null; Transaction tx=null; try{ session=factory.openSession(); tx=session.beginTransaction(); session.save(emp); tx.commit(); System.out.println("Employee Created with empno:--"+emp.getEmpno()); } catch(HibernateException hibernateException){ hibernateException.printStackTrace(); tx.rollback(); System.out.println("Exception is creating an Employee"); } finally{ session.close(); } } public void updateEmployee(Employee emp){ Session session=null; Transaction tx=null; try{ session=factory.openSession(); tx=session.beginTransaction(); session.update(emp); tx.commit(); System.out.println("Employee updated"); } catch(HibernateException hibernateException){ tx.rollback(); System.out.println("Exception in updating Employee"); } finally{ session.close(); } } public Employee getEmployee(int empno){ Session session=null; try{ session= factory.openSession(); Employee emp=(Employee)session.load(Employee.class,new Integer(empno)); return emp; } catch(HibernateException hibernateException){ System.out.println("Exception in loading Employee"); return null; } finally { session.close(); } } public void removeEmployee(Employee emp){ Session session=null; Transaction tx=null; try{ session =factory.openSession(); tx=session.beginTransaction(); session.delete(emp); tx.commit(); System.out.println("Employee Removed"); } catch(HibernateException hibernatteException){ tx.rollback(); System.out.println("Exception in removng Employee"); } finally{ session.close(); } } public static void main(String[] args)throws Exception{ Logger.getRootLogger().setLevel(Level.OFF); HibernateBasicTestCase test = new HibernateBasicTestCase(); Configuration cfg= new Configuration(); cfg.configure(); test.factory=cfg.buildSessionFactory(); Employee emp = new Employee(); emp.setEname("MARK"); emp.setSal(500); emp.setJob("CLERK"); emp.setHiredate(new Date()); emp.setDeptno(20); test.createEmployee(emp); emp.setJob("MANAGER"); emp.setSal(1000); test.updateEmployee(emp); System.out.println(); emp= test.getEmployee(Integer.parseInt(args[0])); if(emp!=null){ System.out.println("Employee Detaiol of empno:" +emp.getEmpno()); System.out.println("Name :"+emp.getEname()); System.out.println("Salary:"+emp.getSal()); System.out.println("Hiredate:"+emp.getHiredate()); } System.out.println(); if(emp!=null)test.removeEmployee(emp); } }
_____________________________________________________________________
package com.santosh.hibernate;
import java.util.Date;
public class Employee {
private int empno,deptno; private String ename,job; private Date hiredate; private double sal;
public int getEmpno(){return empno;} public void setEmpno(int empno){this.empno=empno;}
public int getDeptno(){return deptno;} public void setDeptno(int deptno){this.deptno=deptno;}
public String getEname(){return ename;} public void setEname(String ename){this.ename=ename;}
public double getSal(){return sal;} public void setSal(double sal){this.sal=sal;}
public String getJob(){return job;} public void setJob(String job){this.job=job;}
public Date getHiredate(){return hiredate;} public void setHiredate(Date hiredate){this.hiredate=hiredate;}
}
_______________________________________________________
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class name="com.santosh.hibernate.Employee" table="emp" lazy="false"> <id name ="empno" type="int"> <column name="empno"/> <generator class="increment"/> </id> <property name ="ename" column="ename"/> <property name="sal" /> <property name="job" /> <property name="hiredate" /> <property name="deptno" /> </class> </hibernate-mapping>
___________________________________________________
<!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="connection.driver_class"> oracle.jdbc.driver.OracleDriver </property> <property name="connection.url"> jdbc:oracle:thin:@localhost:1521:XE </property> <property name="connection.user">system</property> <property name="connection.password">oracle</property> <property name="dialect">org.hibernate.dialect.OracleDialect</property> <mapping resource="Employee.hbm.xml"/> </session-factory> </hibernate-configuration> __________________________________________________ i am setting following class path classpath=.\;c:\hibernate-3.1\hibernate3.jar;c:\hibernate-3.1\lib\commons-logging-1.0.4.jar;c:\hibernate-3.1\lib\dom4j-1.6.1.jar;c:\hibernate-3.1\lib\commons-collections-2.1.1.jar;c:\hibernate-3.1\lib\ehcache-1.1.jar;c:\hibernate-3.1\lib\jta.jar;c:\hibernate-3.1\lib\asm.jar;c:\hibernate-3.1\lib\cglib-2.1.3.jar;c:\hibernate-3.1\lib\log4j-1.2.11.jar;C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar;
|