- Create a method in your DAO/Repository named Exists(YourEntity example) -
In the mapping write a namedQuery named "YourEntity.Exists"
- the query may look like : select count(*) from YourEntity e where
e.NaturalIdProperty1 = :pp1 and e.NaturalIdProperty2 = :pp2
- Implements the Exists method using the named query

If you don't want use HQL you can use Criteria but, in this case where you
have a static query, HQL is better candidate.

2008/12/18 epitka <[email protected]>

>
> Hi,
> I use surrogate keys on my tables, but some tables have columns that
> are unique. For example one cannot create a project that has the same
> name. So I am wondering what is the best way to query using NH to
> check if name already exists in the table, so I can make a check
> rather then catching exception. I do not want to populate the entity
> with that name just return count. Can anybody give example.
>
>
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to