spring - Calling stored function in hibernate -


i have tried multiple ways call stored function in hibernate---

1) via session.dowork callback method

session.dowork(new work() {                                         @override                                         public void execute(connection conn)                                                 throws sqlexception {                                               callablestatement stmt = conn.preparecall("{? = call test(?)}");                                               stmt.registeroutparameter(1, types.integer);                                               stmt.setstring(2, "callindex");                                               stmt.execute();                                               eventval = stmt.getint(1);                                           }                         }); 

this works fine cannot return thing here, doesn't solve purpose.

2) via native query

stringbuilder query = new stringbuilder(); query.append("select test() dual"); sqlquery sqlquery = session.createsqlquery(query.tostring()); list resultlist = sqlquery.list(); events = new arraylist<events>(); object result = null; if (events != null && !events.isempty()) {     (int = 0; < events.size(); i++) {         result = resultlist.get(i);     } } 

this doesn't work , gives me no dialect mapping jdbc type -10, not sure of reason.

3) via named query

my entity class ---

@namednativequeries({     @namednativequery(name = "testcall",             query = "? = call test()",                     hints = {@queryhint(name = "org.hibernate.callable", value = "true" )},            resultclass = events.class             )  }) @entity @table(name = "events") public class events implements serializable {      private static final long serialversionuid = -24850323296832289l;      /** id. */     @id     @column(name = "event_sid")     private integer eventid;      /** processed status. */     @column(name = "event_status")     private string eventstatus;      /** event type. */     @column(name = "event_type_name")     private string eventtype;      /** live event. */     @column(name = "is_live_event")     private integer liveevent;      /** event message. */     @lob     @column(name = "event_message")     private string eventmessage;      public integer geteventid() {         return eventid;     }      public void seteventid(integer eventid) {         this.eventid = eventid;     }      public string geteventstatus() {         return eventstatus;     }      public void seteventstatus(string eventstatus) {         this.eventstatus = eventstatus;     }      /**      * gets event type.      *       * @return event type      */     public string geteventtype() {         return eventtype;     }      /**      * sets event type.      *       * @param eventtype      *            new event type      */     public void seteventtype(string eventtype) {         this.eventtype = eventtype;     }      /**      * gets live event.      *       * @return live event      */     public integer getliveevent() {         return liveevent;     }      /**      * sets live event.      *       * @param liveevent      *            new live event      */     public void setliveevent(integer liveevent) {         this.liveevent = liveevent;     }      /**      * gets event message.      *       * @return event message      */     public string geteventmessage() {         return eventmessage;     }      /**      * sets event message.      *       * @param eventmessage      *            new event message      */     public void seteventmessage(string eventmessage) {         this.eventmessage = eventmessage;     }  } 

the dao through making call have method ---

   public integer callsqlblock(){         int event = 0;         session session = gethibernatetemplate().getsessionfactory().getcurrentsession();         list<events> events = null;         events = session.getnamedquery("testcall").list();         return events.get(0).geteventid();     } 

stored function on db end ---

create or replace  function            test return sys_refcursor p_order_recordset sys_refcursor; begin open p_order_recordset select event_sid,event_status,event_type_name,is_live_event events; return p_order_recordset; end ; 

execution of stored function via named query giving me invalid column index

please let me know going wrong on this, , if possible please provide example also


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -