我收到以下异常:
org.springframework.orm.hibernate3.HibernateSystemException: Named query not known:
Run Code Online (Sandbox Code Playgroud)
实体类标题:
@Entity
@NamedNativeQuery( callable = true, name = "_Foo_SP", query = "call _Foo()", readOnly = true, resultClass = Foo.class )
public class Foo {
//...properties omitted for brevity
}
Run Code Online (Sandbox Code Playgroud)
在hibernate.cfg.xml中:
<mapping
class="com.company.test.Foo" />
Run Code Online (Sandbox Code Playgroud)
在测试类中:
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 …Run Code Online (Sandbox Code Playgroud)