-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Type safety problems while using JDK 1.5 with Hibernate
PostPosted: Tue Feb 19, 2008 2:41 pm 
Newbie

Joined: Tue Feb 19, 2008 2:30 pm
Posts: 10
Hibernate version: Hibernate 3.2.6

JDK version: 1.5

Code between sessionFactory.openSession() and session.close():
List<Message> messages = newSession.createQuery("from Message m order by m.text asc").list();

Eclipse 3.3 warning message:
Type safety: Expression of type List needs unchecked coversion to confirm to List<Message>


org.hibernate.Query.list() seems to return just a raw java.util.List object without using any generics. Does that mean I will have to use a lesser JDK version to compile my program?

Please advise!

Thanks,
How Do I!


Top
 Profile  
 
 Post subject: Re: Type safety problems while using JDK 1.5 with Hibernate
PostPosted: Tue Feb 19, 2008 2:50 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
No. Hibernate code is still compatible with earlier JDKs. You will not have this problem if you use its JPA implementation.


Farzad-


Top
 Profile  
 
 Post subject: Re: Type safety problems while using JDK 1.5 with Hibernate
PostPosted: Tue Feb 19, 2008 3:14 pm 
Newbie

Joined: Tue Feb 19, 2008 2:30 pm
Posts: 10
farzad wrote:
No. Hibernate code is still compatible with earlier JDKs. You will not have this problem if you use its JPA implementation.

Farzad-


Thanks for the reply Farzad. Can you please elaborate. I am very new to Hibernate and am working my way through the book "Java Persistence with Hibernate". I downloaded hibernate-3.2.6.ga.zip and am using JDK 1.5 (which causes the Generics related warning messages). When you said that I need to use a JPA implementation of Hibernate, do I need to download a different package? Or do you mean I need to use javax.persistence package classes somehow. I'm sure you can see how lost I am. :)

Thanks!


Top
 Profile  
 
 Post subject: Re: Type safety problems while using JDK 1.5 with Hibernate
PostPosted: Tue Feb 19, 2008 4:40 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
JPA is a Java spec and hibernate has a Java spec. It is a little bit different from doing standard hibernate and you do need extra libraries from the hibernate site to get it going. You might want to look at hibernate's entity manager extension, and for JPA tutorial just google JPA and you will get thousands of pages. However, since you are learning now, you don't really need it now. I would say just live with that warning and later you can move to a JPA solution if you need.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 4:53 pm 
Newbie

Joined: Mon Mar 05, 2007 4:38 am
Posts: 17
If you can't live with the warning or find it annoying, you can either switch it off in eclipse or just add the following just above the start of your method:

@suppresswarnings("unchecked")

It's a rather normal thing to do as API's (such as Hibernate's) try to keep backward compatibility and it will therefore not be possible to fix the unchecked type warnings.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 6:34 pm 
Newbie

Joined: Tue Feb 19, 2008 2:30 pm
Posts: 10
tomba wrote:
If you can't live with the warning or find it annoying, you can either switch it off in eclipse or just add the following just above the start of your method:

@suppresswarnings("unchecked")

It's a rather normal thing to do as API's (such as Hibernate's) try to keep backward compatibility and it will therefore not be possible to fix the unchecked type warnings.


Thanks for the replies Farzad and tomba.

For now,I have used @SuppressWarnings("unchecked") to supress the eclipse warning messages. I will also learn about JPA as Farzad suggested.

Thanks guys, you have been of great help. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.