-->
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.  [ 5 posts ] 
Author Message
 Post subject: Stored procedure mapping problem
PostPosted: Fri Oct 12, 2007 4:39 am 
Newbie

Joined: Mon Jul 30, 2007 5:03 am
Posts: 8
My problem is that i have a result set returned from an oracle stored procedure , and i do not have an id field ( in that particular resultset ) .
How can i generate an id field localy ? Because it seems that the <class> mapping cannot do without an id field .

Mapping documents:
Code:
    <class name="ro.iss.view.chart.AdHocReportMonthly" table="ad_hoc_report">
        <id name="id" type="java.lang.Long">
         <generator class="native"/>
      </id>
       <property name="refDate" column="ref_date" type="java.lang.String" />
      <property name="processType" column="process_type" type="java.lang.String" />
      <property name="donor" column="donor" type="java.lang.String" />
      <property name="status" column="status" type="java.lang.String" />
      <property name="amount" column="amount" type="java.lang.Integer" />
   </class>

Code between sessionFactory.openSession() and session.close():
Code:
session = HibernateUtil.getCurrentSession();
      Query portinstatus =session.getNamedQuery("monthly_report");
      portinstatus.setParameter("status", "%" );
      portinstatus.setParameter("fromdate", "09-10-2007");
      portinstatus.setParameter("todate", "11-10-2007");
      portinstatus.setParameter("process_type", "%");
      portinstatus.setParameter("donor_id","%");
      portinstatus.setParameter("target_date","START_DATE");
      portinstatus.setParameter("granularity","NUMBER");
      logger.debug("\n"+portinstatus.toString());
      logger.debug("Getting list () ");
      portInStatusList = portinstatus.list();


Full stack trace of any exception that occurs:
Code:
[LongType][12 Oct 2007 11:34:38.848][Thread http-0.0.0.0-8080-1][ INFO] could not read column value from result set: id19_0_; Invalid column name
[AbstractBatcher][12 Oct 2007 11:34:38.849][Thread http-0.0.0.0-8080-1][DEBUG] about to close ResultSet (open ResultSets: 1, globally: 1)
[AbstractBatcher][12 Oct 2007 11:34:38.849][Thread http-0.0.0.0-8080-1][DEBUG] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[AbstractBatcher][12 Oct 2007 11:34:38.849][Thread http-0.0.0.0-8080-1][DEBUG] closing statement
[JDBCExceptionReporter][12 Oct 2007 11:34:38.859][Thread http-0.0.0.0-8080-1][DEBUG] could not execute query [{ call AD_HOC_REPORT_MONTHLY( ? ,?,?, ?,?, ? ,
?,?) }]
java.sql.SQLException: Invalid column name
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
        at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:5971)
        at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1527)
        at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1540)
        at org.hibernate.type.LongType.get(LongType.java:28)
        at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
        at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)


Name and version of the database you are using:
Oracle 10g


Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 12, 2007 4:40 am 
Newbie

Joined: Mon Jul 30, 2007 5:03 am
Posts: 8
Excuse me , i forgot :)

the Hibernate mapping involved

Code:
 
<sql-query name="monthly_report" callable="true" >
     <return alias="rep" class="ro.iss.view.chart.AdHocReportMonthly">
    <return-property name="reference_date" column="ref_date" ></return-property>
    <return-property name="process_type" column="process_type" ></return-property>
    <return-property column="donor" name="donor"></return-property>
    <return-property column="status" name="status"></return-property>
    <return-property column="amount" name="amount"></return-property>
    </return>
   { call AD_HOC_REPORT_MONTHLY( ? ,:status,:process_type, :donor_id,:granularity, :fromdate , :todate,:target_date) }
    </sql-query>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 3:45 am 
Newbie

Joined: Mon Oct 16, 2006 11:50 am
Posts: 2
Location: Mumbai, India
I am having the same issue - let me know if you find an answer.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 6:35 pm 
Newbie

Joined: Thu Nov 08, 2007 1:19 pm
Posts: 2
Location: New York
did anyone ever get back to you? i'm having the same issue[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 10:55 am 
Newbie

Joined: Thu Nov 08, 2007 1:19 pm
Posts: 2
Location: New York
HEY!! i found a solution to this problem. what i did was send my results to a temp table that i created with an identity collumn. In sybase this would auto matically add an unique number to the row. then returned a select from teh temp table. i then mapped my id to the newly created identity collumn and it worked great. heres the code....

I started my stored procedure with this:

Create Table #tmp (
dummyId numeric(5,0) identity,
TradingEntityId Char(10) Null,
PartyA_Abbrev Char(5) Null,
Negotiator Char(60) Null,
)


then a bunch of SP code that put its results in teh temp table


and finished my stored procedure with this

Select
dummyId,
TradingEntityId,
PartyA_Abbrev,
Negotiator
From
#tmp


my mapping file looked like this:

<class name="MasterData" mutable="false">
<id name="dummyId"/>
<property name="tradingEntityId"/>
<property name="partyA_Abbrev"/>
<property name="negotiator"/>
</class>

<sql-query name="pr_EMAF_Acct_Search_SP" callable="true">
<return alias="myMasterData" class="MasterData">
<return-property name="dummyId" column="dummyId"/>
<return-property name="tradingEntityId" column="TradingEntityId"/>
<return-property name="partyA_Abbrev" column="PartyA_Abbrev"/>
<return-property name="negotiator" column="Negotiator"/>
</return>
{ call pr_EMAF_Acct_Search_test(:srchId,:srchName) }
</sql-query>


hope this helps you. it worked for me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.