-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hibernate jpa stored procedure
PostPosted: Fri Jun 05, 2015 10:07 am 
Newbie

Joined: Fri Jun 05, 2015 9:58 am
Posts: 1
Hello,

I'm using jpa 2.0 with hibernate persistence provider and I'm trying to call a stored procedure with a custom type parameter (represented in oracle as a type of array of another type).
I can't find any working example of how this can be accomplished.

What I've done so far:
1. Annotated my entity with
@org.hibernate.annotations.NamedNativeQuery(name = "TESTPROCEDURE",
query = "call TESTPROCEDURE(?, :block_array, :ID)",
callable = true, readOnly = true,
resultClass=ResultMappingSP.class)

2. Created an object that will compose the array Block
3. Created a class that implements UserType, Block_Array_Type and implemented nullSafeGet/nullSafeSet

@Override
public Object nullSafeGet(ResultSet rs, String[] names, Object arg2) throws HibernateException,
SQLException {
Array array = rs.getArray(names[0]);
Block[] javaArray = (Block[]) array.getArray();
return javaArray;
}

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
if (value == null)
st.setNull(index, 0);
else {
st.setArray(index, (Array) value);
}
}


However I can't figure out how to call the named query,
I'm thinking something like (where array is a Block[] ):
Query query = em.createNamedQuery("TESTPROCEDURE");
query.setParameter(block_array, array);
query.setParameter("ID", id);

return (ResultMappingSP) query.getSingleResult();

The above code does not work. Please help.
Thank you


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.