I am trying to use hibernate with annotations. I annotated my class with @Entity (Made sure that this is javax.persistance.Entity instead of Hibernate’s entity) and @Table.
When I am trying to query the table with
session.createQuery("from HibernateMatchedInvoiceItem").list()
But this is failing with following exception
caused by: org.hibernate.hql.ast.QuerySyntaxException: HibernateMatchedInvoiceItem is not mapped [from HibernateMatchedInvoiceItem]
my session factory is defined as follows.
<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" />
I didn’t define persistant.xml file. Is it the reason behind this exception?
My doubt is that, since everything hibernate wants(database connection & class mapping) is specified through configuration and annotations, why do we need to specify persistance.xml file explicitly?
If you’re using annotations then you have to use class=”org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean”
Example :