gpt4 book ai didi

java - Hibernate 实体类未拾取

转载 作者:行者123 更新时间:2023-12-02 07:29:36 25 4
gpt4 key购买 nike

我正在尝试使用带注释的 hibernate 。我用 @Entity 注释了我的类(确保这是 javax.persistance.Entity 而不是 Hibernate 的实体)和 @Table。

当我尝试使用

查询表时
session.createQuery("from HibernateMatchedInvoiceItem").list()

但是由于以下异常而失败

caused by: org.hibernate.hql.ast.QuerySyntaxException: HibernateMatchedInvoiceItem is not mapped [from HibernateMatchedInvoiceItem]

我的 session 工厂定义如下。

   <bean id="SessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
parent="AbstractSessionFactory" depends-on="AppConfigHelper">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
</props>
</property>
<property name="dataSource" ref="dataSource" />

我没有定义 persistant.xml 文件。这是这个异常(exception)背后的原因吗?我的疑问是,既然hibernate想要的一切(数据库连接和类映射)都是通过配置和注释指定的,为什么我们需要显式指定persistance.xml文件?

最佳答案

如果您使用注释,那么您必须使用 class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"

示例:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="annotatedClasses">
<list>
<value>package.classname</value>
</list>
</property>

关于java - Hibernate 实体类未拾取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13092296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com