Hi All,
In one my projects we had lot of DAO classes. It was tedious to code hibernate codes all the time into every one of these classes. So I ended
up writing a generic base class. This class had methods like :
-- saveObject(Object obj) throws SomeException
-- Object getObject(Class jClass, Serializable primKey) throws SomeException
-- Object getObjectByHql(String hqlStr) throws SomeException
-- List getObjectListByHql(String hqlStr, Map valMap) throws SomeException
-- Object getObjectByHql(String hqlStr, Map valMap) throws SomeException
, etc.
While saveObject and getObject methods are trivial, the getObjectListByHql and getObjectByHql methods are not. And these
saved a tons of lines of code. If you have hundred DAO classes, it will
easily save you thousand lines of code. The DAO sub-classes will call
these methods in stead of writing codes like :
Query query = session.createQuery(hqlStr);
query.setString(key, value);
query.setInteger(key, value);
etc.
The getObjectListByHql methods can be further abstracted by defining
methods like :
-- getObjectListByHql (String hqlStr, String key, Object value)
-- getObjectListByHql (String hqlStr, String key1, Object value1, String key2, Object value2)
etc.
Has anyone done this? Was there any issue with that?
Thanks,
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:[3.0.5]
[b]Mapping documents:
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: