Adding an entity in a generic way using Hibernate

/ Published in: Java
Save to your folder(s)

Copy this code and paste it in your HTML
  1. public <T> T add(final T obj) {
  2. return get(obj.getClass(), (Long) getHibernateTemplate().save(obj));
  3. }
  4. public final <T> T get(final Class<T> clazz, final Long id) {
  5. return (T) getHibernateTemplate().get(clazz, id);
  6. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.