Announcement Announcement Module
Collapse
No announcement yet.
HibernateTemplate.findByNamedQuery, unique query names? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateTemplate.findByNamedQuery, unique query names?

    I quite like the idea of findByNamedQuery, allowing me to put the query in the mapping file (or XDoclet tags) instead of in my DAO. It strikes me, though, that if one uses this method, then one has to somehow ensure uniqueness of the query name across an application. That is, when you use it, you just specify the query name, and not the mapping file it comes from. If you have the same query name in different mapping files (as indeed you might - "SelectAll", for example), then how does Spring know which one to choose?

    Have I missed something here or is this just something I have to be careful when using?

  • #2
    how does Spring know which one to choose?
    Spring does not check to ensure that quries name are unique. This is managed by Hibernate itself, and of course the responsability of the developer.
    I think, however, that Hibernate throws an exception while initializing its SessionFactory if it encounter two queries with the same name.

    Comment


    • #3
      I'm happy if an error is flagged at that point, rather than in runtime. It's probably worth taking the risk, then.

      Comment

      Working...
      X