views:

387

answers:

1

I do not use HibernateTemplate, but work with getCurrentSession() in my DAO.

I would like to know how to declare Hibernate named queries in a beans.xml file (I do not use hbm.xml).

And maybe Spring has alternative means to declare Hibernate named queries?

+1  A: 

You can put named queries on the entity using annotations:

@NamedQueries({@NamedQuery(name="Entity.findAll", query="....")})

Also, if using JPA, there's orm.xml, The XSD tells us that you can use:

<named-query name="Entity.findAll">
   <query><![CDATA[SELECT e FROM Entity e]]</query>
</named-query>
Bozho
@Bozho Well I do not use orm.xml as I said. You can put all your hibernate settings, including mapping classes directly to spring beans.xml file. So I wonder how to put a named query THERE. But @NamesQueries annotation looks better, where do you put it? Right into DAO code?
EugeneP
Put it on the entity class. And you said you don't use hbm.xml, not orm.xml. I somehow assumed you are using JPA xml files (because beans.xml isn't the default name in spring).
Bozho