9

Is there a reason Hibernate doesn't use generics? If it did it would save developers a lot of casts.

Example Hibernate code:

Customer aCustomer = (Customer) session.load(Customer.class, 1L);
...
Criteria criteria = session.createCriteria(Customer.class);
Customer aCustomer = (Customer) criteria.uniqueResult();

With proper use of generics it would become:

Customer aCustomer = session.load(Customer.class, 1L);
...
Criteria<Customer> criteria = session.createCriteria(Customer.class);
Customer aCustomer = criteria.uniqueResult();
adrianboimvaser
  • 2,651
  • 1
  • 22
  • 30
  • possible duplicate of [How to avoid type safety warnings with Hibernate HQL results?](http://stackoverflow.com/questions/115692/how-to-avoid-type-safety-warnings-with-hibernate-hql-results) -- see Paulo Merson's answer – mindas May 10 '13 at 09:41

1 Answers1

0

Hibernate has been around since 2001, but generics were added in 2005. And maybe the Hibernate designers are slow to adopt new techniques? or maybe they are very concerned about backward compatibility?

John Henckel
  • 10,274
  • 3
  • 79
  • 79