• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error saving objects in oracle

 
Gauss Jordan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to hibernate. To get familiar with hibernate, I tried tutorial at http://homepage.mac.com/edahand/projects/java/example1.html. Although this tutorial is for mysql, I changed the hinernate properties to use oracle.

hibernate.dialect net.sf.hibernate.dialect.OracleDialect
hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
#hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc racle:thin:@localhost:1521:***
hibernate.connection.username scott
hibernate.connection.password tiger


The table I created is :
CREATE TABLE item (
id number NOT NULL,
name varchar2(32) NOT NULL,
description varchar2(32),
PRIMARY KEY (id)
);


I changed generator class from 'identity' to 'native' as I read that oracle9i does not support 'identity'.

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

<hibernate-mapping>
<class name="com.edhand.example1.Item" table="item" >
<id name="id" column="id" type="java.lang.Long" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="description" column="description" type="java.lang.String" />
</class>
</hibernate-mapping>

Everything works fine till I try to save the object. Hibernate is connecting to oracle 9i, but when I try to add new data it gives me exception:

javax.servlet.ServletException: net.sf.hibernate.JDBCException: Could not save object
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.RuntimeException: net.sf.hibernate.JDBCException: Could not save object
com.edhand.example1.ItemService.addItem(Unknown Source)
com.edhand.example1.AddItemAction.execute(Unknown Source)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


I would appreciate if somebody could help me what this exception means and how to get rid of it.

Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic