我正在嘗試在註釋中使用hibernate。我用@Entity註釋了我的類(確保這是javax.persistance.Entity而不是Hibernate的實體)和@Table。Hibernate實體類不拾起
當我試圖查詢該表與
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文件。這是這個例外背後的原因嗎? 我的疑問是,因爲休眠所需的一切(數據庫連接&類映射)是通過配置和註釋指定的,爲什麼我們需要明確指定persistance.xml文件?
你確定創建HibernateMatchedInvoiceItem表在你的數據庫? –
HibernateMatchedInvoiceItem類用@Table註解(name =「matched_invoices」),而matched_invoices表有一些行。如果我正在使用簡單的jdbc模板而不是使用hibernate,這會給出結果。 – Htaras