Basically what I'm trying to do is a call to Oracle stored procedure using Hibernate. Procedure takes two IN parameters, creates object of Oracle type User (it has two fields - id and name) and returns it via OUT parameter. My Java call is:
ProcedureCall call = session.createStoredProcedureCall("get_obj");
call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L);
call.registerParameter(2, String.class, ParameterMode.IN).bindValue("John");
call.registerParameter(3, User.class, ParameterMode.OUT);
Java class is simple POJO class with same fields, setters and getters. Is there a way to convert Oracle types to Java and vice versa?
As per Using Customized Type Mappings you should create a User
class by implementingSQLData
interface:
public class User implements SQLData {
// fields
// readSQL
// writeSQL
}
and then use Connection.setTypeMap()
to setup the mapping for new User
type.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.