-->
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: Stored Procedure
PostPosted: Mon Mar 14, 2005 2:50 pm 
Newbie

Joined: Mon Mar 14, 2005 2:42 pm
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 3:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
my guess is that hibernate sets the id last and the property first onto the insert. At the moment the sequence of parameters need to obey how hibernate wants them.

you can see what sequence hibernate expects by enable debug log for org.hibernate.persister.entity and you should see the expected sql (remember to disable your own overriding sql while doing this!)

The log output should start with something like:
"Static SQL for entity"

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 6:16 pm 
Newbie

Joined: Mon Jun 07, 2004 12:59 pm
Posts: 13
I got this same error when trying to get the example in the reference manual to work. When I reversed the order of the parameters in the stored procedure (function), the error went away.

Regards,
Allan M. Hart


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.