Hi
I am using
Hibernate Annotations Version: 3.3.0.GA (as seen in MANIFEST.MF) to annotate entity classes. Now, I want to be able to call an stored procedure which returns just an integer value (actually, this is to check some value and return 0 o 1 depending on the check is successful or not).
Well, I have the following code to declare the stored procedure, actually a function, and be able to call it from my program:
Code:
@NamedNativeQuery(name="checkValue", callable=true,
query="? = call checkValue (:myvalue)",
resultClass = Integer.class)
This annotation is in the top of an entity class, and when hibernate is setting the configuration for the annotated classes (at startup time) I get this exception:
Code:
2009-06-22 18:47:39,010 ERROR SessionFactoryImpl.<init>:363 - Error in named query: checkValue
org.hibernate.MappingException: Unknown entity: java.lang.Integer
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:312)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:353)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:332)
at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:148)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:64)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:446)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:352)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at (...)
I have been searching on internet but I didn't get anything more or less clear about this problem.
May I actually use stored functions or procedures and call them from hibernate? Does hibernate support stored functions returning just scalar values? Do I have anything wrong in the declaration?
The only example with scalars I have found is on the annotations tutorial but it is quite unuseful for me as they don't use a true stored function.
Thanks in advance and apologies if this is a fool question.
w i l l y