Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
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();
}
}
}
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.