我正在尝试使用带有注释的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]
我的会话工厂定义如下。
<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文件?
答案 0 :(得分:2)
如果你正在使用注释,那么你必须使用class =&#34; org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&#34;
示例:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="annotatedClasses">
<list>
<value>package.classname</value>
</list>
</property>