简体   繁体   English

更新到hibernate 5.0.7和jpa 2.1之后,hibernate命名查询错误

[英]hibernate named query error after updating to hibernate 5.0.7 and jpa 2.1

I have very simple named query that use to work before update but now I am getting runtime error. 我有一个非常简单的命名查询,该查询在更新之前可以工作,但是现在出现运行时错误。

this is the named query : 这是命名查询:

@Entity
@Table(name="FRA_HIER_NODE_TYPE", schema="FRA_DATA")
@NamedQuery(name="NodeType.FetchNodeTypes", query="FROM NodeType")
public class NodeType {
...

The exception i see : 我看到的异常:

Caused by: org.hibernate.HibernateException: Errors in named queries: NodeType.FetchNodeTypes
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:493)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
    at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:416)
    at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:401)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 25 more

You should use something like this : 您应该使用这样的东西:

@Entity
@Table(name="FRA_HIER_NODE_TYPE", schema="FRA_DATA")
@NamedQuery(name="NodeType.FetchNodeTypes",query="SELECT * FROM NodeType") 

Hope this Helps. 希望这可以帮助。

Did you try this: 您是否尝试过:

@Entity
@Table(name="FRA_HIER_NODE_TYPE", schema="FRA_DATA")
@NamedQuery(name="NodeType.FetchNodeTypes",query="SELECT n FROM NodeType n")

Are you declaring your own SessionFactory for Hibernate? 您是否在为Hibernate声明自己的SessionFactory I don't remember how Hibernate works with Spring. 我不记得Hibernate如何与Spring一起工作。

But if you have with hibernate config you may have lines like this: 但是,如果您具有休眠配置,则可能会出现如下所示的行:

<mapping class="com.example.NodeType" />

This is removed in Hibernate 5. Instead you have to declare your entities in code when building SessionFactory . 在Hibernate 5中已将其删除。相反,在构建SessionFactory时必须在代码中声明实体。 For example: 例如:

        StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
            .configure()
            .build();

        Metadata metadata = new MetadataSources(standardRegistry)
            .addAnnotatedClass(NodeType.class)
            .getMetadataBuilder()
            .applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE)
            .build();

        sessionFactory = metadata
            .getSessionFactoryBuilder()
            .build();

See more: http://docs.jboss.org/hibernate/orm/5.0/userGuide/en-US/html_single/#bootstrap-native-sessionfactory 查看更多: http : //docs.jboss.org/hibernate/orm/5.0/userGuide/zh-CN/html_single/#bootstrap-native-sessionfactory

Maybe there is some SessionFactory builder for Spring that you now have to configure similary. 也许现在有一些用于Spring的SessionFactory构建器,您必须配置相似性。 If so, please post your new config for others. 如果是这样,请为他人发布您的新配置。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM