-->
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.  [ 2 posts ] 
Author Message
 Post subject: Java 5.0 Compliance with generics and queries
PostPosted: Sat Sep 24, 2005 4:23 pm 
Newbie

Joined: Fri Sep 16, 2005 5:14 pm
Posts: 3
Location: Frisco Texas
java 5.0 update 4
Hibernate 3.1
Eclipse 3.1

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>

the below works fine (as a test of code conformation), Eclipse on the other hand is not letting me add the second pair of <xxx> type brackets without telling me that its an error. I've tried the secord pair of brackets in six places.

[code]

void doIt() {
List <Yo>a = new ArrayList<Yo>();
a.add(new Yo("yo"));
a.add(new Yo("ho"));

ArrayList <Yo>b = new ArrayList<Yo>(a);

Iterator <Yo>c = b.iterator();
while(c.hasNext()) {
Yo d = c.next();
System.out.println(d.getName());
}
}

[code]


Any information would be helpful.

Thanks, Tom[/code]

_________________
The first place you go blind is in your eyes


Top
 Profile  
 
 Post subject: Re: Java 5.0 Compliance with generics and queries
PostPosted: Mon Sep 26, 2005 10:22 am 
Newbie

Joined: Thu May 26, 2005 11:46 am
Posts: 4
Location: London UK
Thomas Bigbee wrote:
the below works fine (as a test of code conformation), Eclipse on the other hand is not letting me add the second pair of <xxx> type brackets without telling me that its an error. I've tried the secord pair of brackets in six places.

I'm not entirely sure what you mean here, but your code compiles fine in eclipse for me. Here's a simpler example which should work:


Code:
void doIt() {
        List <Integer>a = new ArrayList<Integer>();
        a.add(new Integer(1));
        a.add(new Integer(2));

        ArrayList <Integer> b = new ArrayList<Integer>(a);
        for(Integer i : b) {
            System.out.println(i);
        }
    }


I have turned off these warnings in Eclipse by using "Preferences" / "Java" / "Compiler" / "Errors/Warning" / "J2SE 5.0 options" and selecting Ignore for "unchecked generic type operation".

HTH


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.