Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making Hibernate 5.0 Compliant

 
Thomas Bigbee
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody have any examples of using generics (java 5.0) with Hibernate 3.1, any queries I do, I have to preface the method call with @SuppressWarnings("unchecked"), I'd really like to be to get rid of that annotation. I've almost got it, except for the Session.createQurey() method.

List <Honey>honeys =session.createQuery(
"from Honey order by name").list();

gives me the warning: Type safety, the expression of type list needs unchecked conversion to conform to List<Honey>

Any information would be helpful.

Thanks, Tom
[ September 24, 2005: Message edited by: Thomas Bigbee ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Hibernate supported generics internally then Hibernate would be limited to JVM 1.5+, which it is not.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came accross this blog post by Christian a while ago. I haven't had time to go through it yet, It is probabely off topic, but may be of use to you -

Generic DAO pattern with JDK 5.0
 
Thomas Bigbee
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found out why I could not use Generics on sets and lists returned from hibernate queries

From Hibernate Quickly..

Hibernate provides its own implementation of the Collections interfaces

Hibernate implements the Collections interfaces in the java.util package. When Hibernate populates a collection, such as a java.util.List, the implementing class is actually org.hibernate.collection.List.
 
Christian Bauer
author
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you can use generics on any List, Set, Collection, or Map, that is managed by Hibernate. If those standard interfaces are not enough, you can as well extend Hibernate by implementing the PersistentCollection interface.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic