-->
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.  [ 34 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Stored procedure support in Hibernate3
PostPosted: Wed Nov 17, 2004 4:25 pm 
Newbie

Joined: Wed Nov 17, 2004 4:17 pm
Posts: 9
Does hibernate 3 supports "read" in Stored procedure. I know that hibernate has provided support for Stored procedures in 3.0, but is it only for <sql-create callable = true> <sql -update callable = true> and <sql-delete callable = true>.
but what about 'Read' how can I use a stored procedure to read from the DB2 database ?

any help is appretiated .

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 4:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Currently we haven't implemented read support for Stored procdures, primarily because the different vendors require different code for doing it.

The best option at the moment is to write a custom persister/loader for it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 6:44 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#execute(java.lang.String)



This is standard way, you need trivial adapter if driver provider fails to implement it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 6:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
AFAIK Oracle doesn't support that one - that's the problem ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 6:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and the adapter is not trivial for oracle as one has to call a method on a native oracle class - and we don't wanna have code in H2 dependent on oracle jdbc.jar

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 7:01 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Yes, do not add any dependancies on drivers, just add pluggable adapter factory:

interface ConnectionAdapterFactory {

Connection getAdapter(Connection cnn);

}

default implemantation can be

Connection getAdapter(Connection cnn){

return cnn;

}

It must be better than to fork pool implementations or depend on drivers,
it will work for user provided connections too.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 7:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well - yes, but the reason i haven't done this yet is that returning resultset's from stored procedures is done AFAIK 3 different ways...standard, db2 and oracle....and all three vary in different aspects in the 3 areas: how to prepare the callable statement, how to execute and how to retreive the result from it....and it should be done so it is compatible with executing normal sql.....

...and yes, an adapter could be written - and probably will - but it is not the primary focus right now ;) ....patches are welcome!

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 8:22 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
As I understand callable statements are important for "out" parametrs only, but this is valid way to call stored procedure too:

PreparedStatement ps = con.prepareStatement( "{call myProc(?)}" );

if(ps.execute()){
ps.getResultSet();
}

"{call ? = myProc(?)}" this must return result set as "out" parameter in callable statement.

Probably you need to define adapter conventions for hibernate too, it can not be clear from JDBC and ODBC specifications how to implementa adapter for hibernate (adapter interface doe's not need to be JDBC connection too, I think it is better to define custom adapter interface )


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 9:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - but "{call ? = myProc(?)}" is exactly the syntax (at least) oracle want for returning something (here a ResultSet) from a SP.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 10:37 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I hope it is possible use stored procedure as "inline view"
SELECT * FROM myProc(?,?) in oracle too, but probably it is not so important, user can implement adapter himself.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 10:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm .... i haven't seen that kind of syntax suggested before...is it as effiecient as { call ? = myView(x,y) } ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 11:14 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I have not tried it on oracle, it works on postgresql, but most databases suppor inline views. I know oracle supports inline views, but I am not sure it can be a procedure result. It must be better to try it, but I do not have oracle instance at this time.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 05, 2004 8:26 pm 
Beginner
Beginner

Joined: Fri Sep 24, 2004 8:18 am
Posts: 24
max wrote:
... AFAIK 3 different ways...standard, db2 and oracle....

If there are more than one way to return a result set from a stored proc, don't you think you need something similar to SQL Dialect,i.e. StoredProc Dialect, ?

In my opinion, there are 2 types of return when executing a stored proc :
1. return a non-result-set, where the last SQL statement is not a SQL SELECT statement.
2. return a result-set, where the last SQL statement is a SQL SELECT.

I could be wrong ...

nusa


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 05, 2004 8:31 pm 
Beginner
Beginner

Joined: Fri Sep 24, 2004 8:18 am
Posts: 24
max wrote:
yes - but "{call ? = myProc(?)}" is exactly the syntax (at least) oracle want for returning something (here a ResultSet) from a SP.


Are you sure ?
Download the Oracle JDBC demo file ( demo.tar ), untar it, then have a look these files : samples/generic/PLSQL*.java

nusa.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 3:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - could you give me a link to that demo.tar ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 34 posts ]  Go to page 1, 2, 3  Next

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.