I am getting the following exception:
org.springframework.orm.hibernate3.HibernateSystemException: Named query not known:
Entity class header:
@Entity
@NamedNativeQuery( callable = true, name = "_Foo_SP", query = "call _Foo()", readOnly = true, resultClass = Foo.class )
public class Foo {
//...properties omitted for brevity
}
In the hibernate.cfg.xml:
<mapping
class="com.company.test.Foo" />
And in a test class:
private static HibernateTemplate HIBERNATE_TEMPLATE;
public static void main( final String[] args ) {
HIBERNATE_TEMPLATE =
new HibernateTemplate( new AnnotationConfiguration().addAnnotatedClass( Foo.class ).configure().buildSessionFactory() );
new HibernateTest().test();
}
public void test() {
List findByNamedQuery = HIBERNATE_TEMPLATE.findByNamedQuery( "_Foo_SP" );
for( Object object : findByNamedQuery ) {
System.out.println( object );
System.out.println( object.getClass().getName() );
}
}
I had this working without annotations (eg: with the mapping in a mapping file) but it seems more intuitive to simply use the JPA annotations to declare mappings - but I can't seem to get it to work.
What am I doing wrong here? Is what I'm trying to do even possible? It seems I'm not the only one to encounter this, see: here.
I'm using hibernate 3.5.6-FINAL FWIW.
TIA
The problem was that I was using the wrong @Entity class. When I used:
org.hibernate.annotations.Entity
I would get the problems above. However, once I switched to:
javax.persistence.Entity
It works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With