0

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

当我试图用

session.createQuery("from HibernateMatchedInvoiceItem").list()

但这失败了,但有以下例外

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

我的会话工厂定义如下。

   <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 文件。这是这个例外背后的原因吗?我的疑问是,既然hibernate想要的一切(数据库连接和类映射)都是通过配置和注释指定的,为什么我们需要明确指定persistance.xml文件?

4

1 回答 1

2

如果您使用注释,那么您必须使用 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>
于 2012-10-26T18:34:01.130 回答