views:

539

answers:

0

The code schematic below works fine but it breaks our coding guidelines due to the unchecked cast. How can this be re-written to use createQuery or otherwise avoid the unchecked cast?
Note 1: using hibernate
Note 2: @SuppressWarnings("unchecked") is not the answer

@Entity @Table(name="Foo") class Foo {
   @EmbeddedId FooPK pk;
   ...
}
@Embeddable class FooPK {
   int id;
   int category;
   ...
}

To select items of a given category we use

Query q = createNativeQuery("select * from Foo f where f.id=?", Foo.class)
    .setParameter(1,fooCat);
for(Object o : q.getResultList()) {
    doSomething( (Foo)o );  // no-no