Hi,
I am trying to pass an Oracle Type object to a stored procedure. It works fine when i use plain JDBC, but using hibernate has become a challenge. Can anyone please guide me towards the right direction.
UserTypeType implements UserType
Here is what i am trying to do:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
java.sql.Connection conn = session.connection();
PreparedStatement ps = conn.prepareStatement("call user_pkg.ADD_NEW_USER(?,?)"); // dont know if creating this is right, it was done because nullSafeSet() requires a preparedStatement .
User user = new User();
user.setUserName("user6");
user.setFirstName("fname2");
user.setLastName("lname2");
user.setEmail("email2");
user.setPassword("password");
user.setAccessRoleId(new Integer(4));
user.setAssignedRoleId(new Integer(5));
user.setActive("Y");
UserTypeType type = new UserTypeType();
type.nullSafeSet(ps, user, 1);
Query qry = (Query)session.getNamedQuery("addNewUser");
qry.setParameter(1, type, Hibernate.custom(UserTypeType.class));
Object obj = qry.uniqueResult();
xml mapping
<sql-query name="addNewUser" callable="true">
{ call user_pkg.ADD_NEW_USER(?,?) }
</sql-query>
|