0

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?

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
EugeneP
  • 11,783
  • 32
  • 96
  • 142

1 Answers1

1

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
  • 588,226
  • 146
  • 1,060
  • 1,140
  • @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 Apr 18 '10 at 16:37
  • 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 Apr 18 '10 at 21:54