Hi all,
I have a question regarding the stored procedures in JPA. I have the following Entity called RenGaraza which uses two stored procedures "vrniGarazo" and "vrniGarazoPk" that do basically the same thing. The only difference is in the were part of the procedure - the resultSet is the same in both cases.
Code:
@SuppressWarnings("serial")
@Entity
@Table(name = "REN_GARAZA")
@Loader(namedQuery = "vrniGarazoPk" )
@NamedNativeQueries({
@NamedNativeQuery(name = "vrniGarazoPk", query = "{ call API_PVN_DST.vrni_dst_park_pk(?, :vGarId)}", resultClass = RenGaraza.class, hints = { @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") }),
@NamedNativeQuery(name = "vrniGarazo", query = "{ call API_PVN_DST.vrni_dst_park_fk(?, :vDstSid)}", resultClass = RenGaraza.class, hints = { @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })
})
public class RenGaraza implements java.io.Serializable {
...
}
The stuff works just fine when I call the procedure directly using the first named query - "vrniGarazo":
Code:
public void testGaraza_dstsid() {
Query qGaraza = session.getNamedQuery("vrniGarazo");
qGaraza.setParameter("vDstSid", v_dst_sid);
List<RenGaraza> listGaraza = qGaraza.list();
listGaraza.size();
System.out.println("Garaza, st. zapisov: " + listGaraza.size());
for (RenGaraza garaza : listGaraza) {
int garId = garaza.getGarId();
System.out.println(" gar_id: " + garId);
assertNotNull(garId);
}
}
However, I need to call the same entity via another Entity "RenDelistavb":
Code:
@Entity
@Table(name = "REN_DELISTAVB")
@Loader(namedQuery = "vrniDelStavbe")
@NamedNativeQueries( {
@NamedNativeQuery(name = "vrniDelStavbe", query = "{ call API_PVN_DST.vrni_dst_dst_pk(?, :vDstSid)}", resultClass = RenDelistavb.class, hints = { @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") }),
@NamedNativeQuery(name = "vrniGarazoDstSid", query = "{ call API_PVN_DST.vrni_dst_park_fk(?, :vDstSid)}", resultClass = RenGaraza.class, hints = { @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") }) })
public class RenDelistavb implements java.io.Serializable {
...
private Set<RenGaraza> renGarazas = new HashSet<RenGaraza>(0);
@Loader(namedQuery = "vrniGarazoDstSid")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "renDelistavb")
public Set<RenGaraza> getRenGarazas() {
return this.renGarazas;
}
...
}
I have tried all kinds of mambo-jumbo like adding the ResultSetMapping to the procedure, adding different loader and so on, but could not make it to work.
I get the NullPointerException and if I do some debugging I can see that "com.sun.jdi.InvocationException occurred invoking method." error. I additionally debuged the procedure that is called in the second case and it sims that it executes correcly even using the correct id from the RenDelistavb and that it actually generates the resultSet, but it is not returned correctly.
I am using the latest version of hibernate (3.4.0.GA)
Now, obviously my question is what am I doing wrong and if it is even possible to call the original clall (RenGaraza ) in the manner I am trying to do it?
If the answer is not, is there any workaround or another solution?
Thanks for the answers.
Regards,
Matej