Hi,
I need to do some complex SQL for report app.
Is it possible to use "getNamedQuery" method to avoid write long SQLs on source code?
I would to do something like the following code:
Code:
List<Company> result = getSession().getNamedQuery("findCompaniesByCode")
.setResultTransformer(new AliasToBeanResultTransformer(Company.class))
.list();
where Company is a simple pojo (without any annotation/mapping).
Then query "findCompaniesByCode" would be placed in a .xml file and loaded by sessionFactory.
My application-context.xml has the following configuration:
Code:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="mappingLocations">
<list>
<value>classpath:*.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> ${hibernate.db.dialect} </prop>
</props>
</property>
</bean>
Does it make sense? Is it possible?
Or namedQuery works only for entity managed by Hibernate?
Any suggestion?
Thanks in advance.
Best,
Rodrigo