I have created a stored procedure :
CREATE OR REPLACE Procedure createCategory (catId In Number ,category IN VARCHAR2) IS
BEGIN
insert into Categories (Category_id,Category) values (catId,category) ;
END ;
///////////////////////////////////////////////////////////////////////////
My Configuration file looks like :
/////////////////////////////////////////////////////////////////////////////
<?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
package="a"
default-access="field">
<class name="CategoriesDTO" table="Categories">
<id name="category_id">
<generator class="increment"/>
</id>
<property name="category" />
<sql-insert callable="true">{call createCategories (? , ?)}</sql-insert>
</class>
</hibernate-mapping>
/////////////////////////////////////////////////////////
Although table Categories has so many columns but i'm interested in inserting into category column.
/////////////////////////////////////////////////
I'm calling it using folowing sample class:
import org.hibernate.Session;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import a.CategoriesDTO;
import java.util.*;
import org.hibernate.connection.ConnectionProviderFactory;
import org.hibernate.connection.ConnectionProvider;
import java.sql.*;
import java.math.BigDecimal;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import org.hibernate.Criteria;
import java.util.*;
import java.util.List;
public class HibernateSample {
public static void main(String[] args) throws Exception {
Configuration config = new Configuration();
// Mapping class
config.addClass(CategoriesDTO.class);
// Get the sesion factory we can use for persistence
SessionFactory sessionFactory = config.buildSessionFactory();
// Hibernate's Session
Session session = sessionFactory.openSession();
Transaction tx = null;
java.io.Serializable courseId ;
// Store a new Static Page in the database.
try
{
int tempId =12121212;
String str="test";
CategoriesDTO categories = new CategoriesDTO();
tx = session.beginTransaction();
categories.setCategory_id(tempId);
categories.setCategory(str);
session.save(categories);
tx.commit();
}
catch(Exception e){
e.printStackTrace();
}
finally
{
// Close our session and release resources
session.flush();
session.close();
}
sessionFactory.close();
}
}
////////////////////////////////////////////////////////////////////////////
getting the following error
/////////////////////////////////////////////////////////////////////////
[color=red]org.hibernate.exception.GenericJDBCException: could not insert: [a.CategoriesDTO] Caused by: java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at line 1[/color]
can some one help me out what is the issue with the above code....
thanks in advance
|