Java 更新到hibernate 5.0.7和jpa 2.1后出现hibernate命名查询错误

Java 更新到hibernate 5.0.7和jpa 2.1后出现hibernate命名查询错误,java,hibernate,jpa,named-query,Java,Hibernate,Jpa,Named Query,我有一个非常简单的命名查询,用于在更新之前工作,但现在我遇到运行时错误 这是命名查询: @Entity @Table(name="FRA_HIER_NODE_TYPE", schema="FRA_DATA") @NamedQuery(name="NodeType.FetchNodeTypes", query="FROM NodeType") public class NodeType { ... 我看到的例外情况是: Caused by: org.hibernate.HibernateExce

我有一个非常简单的命名查询,用于在更新之前工作,但现在我遇到运行时错误

这是命名查询:

@Entity
@Table(name="FRA_HIER_NODE_TYPE", schema="FRA_DATA")
@NamedQuery(name="NodeType.FetchNodeTypes", query="FROM NodeType")
public class NodeType {
...
我看到的例外情况是:

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
原因:org.hibernate.HibernateException:命名查询中的错误:NodeType.fetchnodeType
位于org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:493)
位于org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
位于org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
位于org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
位于org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:416)
位于org.springframework.orm.hibernate5.LocalSessionFactoryBean.AfterPropertieSet(LocalSessionFactoryBean.java:401)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 25多

您应该使用以下内容:

@Entity
@Table(name="FRA_HIER_NODE_TYPE", schema="FRA_DATA")
@NamedQuery(name="NodeType.FetchNodeTypes",query="SELECT * FROM NodeType") 
希望这有帮助。

您是否尝试过以下方法:

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

您是否为Hibernate声明自己的
SessionFactory
?我不记得Hibernate是如何与Spring一起工作的

但是如果您使用hibernate配置,您可能会有这样的行:

<mapping class="com.example.NodeType" />
请参阅更多:

可能有一些Spring的SessionFactory构建器,您现在必须进行类似的配置。如果是这样,请为其他人发布您的新配置


希望这有帮助。

尝试发布更多实体代码
        StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
            .configure()
            .build();

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

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