Loading
CallableStatement Hibernate

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  CallableStatement Hibernate


Ans)

Call Stored Procedure Hibernate :

 
This would illustrates how to call stored procedures
by using Callable Statements and Hibernate .'

In this example "GENERATE_ID" is a Stored Procedure. In the same manner
you can invoke any Stored Procedure

    public String generateId(String idName, Session session) {
        Session newSession = null;
        try {
            newSession = GeneratorSession;
            BigDecimal nextId;
            Connection con = newSession.connection();
            con.setAutoCommit(false);
            CallableStatement cstmt = con.prepareCall("{ call GENERATE_NEXT_ID(?, ?) }");
            cstmt.setString(1, idName);
            cstmt.registerOutParameter(2, java.sql.Types.NUMERIC);
            cstmt.execute();

            nextId = (BigDecimal) cstmt.getObject(2);
            cstmt.close();
            con.commit();
            return nextId.toString();
        } catch (SQLException e) {
            try {
                session.connection().rollback();
            } catch (HibernateException he) {
                throw new HibernateRuntimeException("SQL error", e);
            } catch (SQLException sqlE) {
                throw new HibernateRuntimeException("SQL error", e);
            }
        } catch (org.hibernate.HibernateException e) {
        }
        finally {
            if(newSession != null) {
                newSession.clear();
                newSession.close();
            }
        }
    }



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

CallableStatement Hibernate


CallableStatement Hibernate

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free