Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sybase stored proc error

 
Juzar Roopawalla
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hibernate config file:

<?xml version='1.0'?>
<!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.datasource">
java:/comp/env/jdbc/wg
</property>
<property name="dialect">
org.hibernate.dialect.SybaseDialect
</property>
<property name="current_session_context_class">
thread
</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
<mapping resource="com/msdw/pbefficiency/servicestracker/WGOpportunity.hbm.xml" />
</session-factory>
</hibernate-configuration>

mapping file:

<?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>
<sql-query name="Opps.By.CompanyId" callable="true">
<return alias="opp" class="com.msdw.pbefficiency.servicestracker.hibernate.pojo.Opportunity">
<return-property name="opportunityName" column="opportunityName" />
<return-property name="companyId" column="itemId" />
<return-property name="status" column="status" />
</return>
{ ? = call qryOpportunityByCompanyId (:itemId) }
</sql-query>
</hibernate-mapping>

The moment I try looking up the session factory (jndi), I get the following error:

Initial SessionFactory creation failed.javax.naming.NamingException: Errors in named queries: Opps.By.CompanyId

The proc contents is just a simple select statement. I have checked the return types, column names, class methods etc. Everything is in order.
I also tried to put the proc call like this:

1) { call qryOpportunityByCompanyId (:itemId) }
2) { call qryOpportunityByCompanyId (?) }
3) { ? = call qryOpportunityByCompanyId (?) }

Any help will be appreciated.
 
Shailesh Kini
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Juzar,

Does it have a stack trace? It might be helpful.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what your Sybase Stored Proc looks like, but just want to add that there are some stipulations for you to use any stored procedures with Hibernate

1. There can be only one out parameter and it must be the first parameter.
2. Only Reference Cursors can be returned, no other types.

Mark
[ October 09, 2007: Message edited by: Mark Spritzler ]
 
Juzar Roopawalla
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using this on Sybase
Here is the exception stack trace:

HibernateUtil.java:46 is :

sessionFactoryWG = (SessionFactory) c.lookup("hibernate/wg");

I just cannot understand wht the error is in the Named query.

Oct 9, 2007 10:41:50 AM org.apache.naming.NamingContext lookup
WARNING: Unexpected exception resolving reference
org.hibernate.HibernateException: Errors in named queries: Opps.By.CompanyId
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:339)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at com.msdw.pbefficiency.servicestracker.naming.HibernateSessionObjectFactory.initSessionFactory(HibernateSessionObjectFactory.java:46)
at com.msdw.pbefficiency.servicestracker.naming.HibernateSessionObjectFactory.getObjectInstance(HibernateSessionObjectFactory.java:37)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:129)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:791)
at org.apache.naming.NamingContext.lookup(NamingContext.java:138)
at org.apache.naming.NamingContext.lookup(NamingContext.java:779)
at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
at com.msdw.pbefficiency.servicestracker.utils.HibernateUtil.<clinit>(HibernateUtil.java:46)
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about typing the wrong database name.

Anyway, it doesn't matter which database you use regarding the SP stipulations.

Also, maybe the "." in the named query is what is causing the errors.

Can you post the declaration of the stored procedure in Sybase?

Thanks

Mark
 
Juzar Roopawalla
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
I have tried without the dots too. The error remains the same.
The proc is just a simple select :

select * from Opportunity where id = @cid

I guess returning a cursor is not a restriction that hibernate has for sybase.

One question though, my mapping file just has the sql-query and the class name is not mapped anythere to a <class> element. Is that a problem?

Thanks in advance.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Juzar Roopawalla:
Hi Mark,
I have tried without the dots too. The error remains the same.
The proc is just a simple select :

select * from Opportunity where id = @cid

I guess returning a cursor is not a restriction that hibernate has for sybase.

One question though, my mapping file just has the sql-query and the class name is not mapped anythere to a <class> element. Is that a problem?

Thanks in advance.


Unfortunately it is a restriction for all databases. But what is called a reference cursor in one database is called something else in another database. For instance your procedure is a ref cursor because it is Select * from one table.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic