I think you have to use the Implements annotation. Something like:

        public class MyPerson implements Person {}

-----Message d'origine-----
De : cbeams [mailto:[EMAIL PROTECTED] 
Envoyé : samedi 1 septembre 2007 9:14
À :
Objet : Query by interface

As a user, here's what I would expect to work:

        public interface Person {}

        public class MyPerson implements Person {}

        public class Main {
                public static void main(String... args) {
                        PersistenceManagerFactory pmf =  
                        PersistenceManager pm = pmf.getPersistenceManager();
                        pm.makePersistent(new MyPerson());  // persist the
concrete type

                        Query query = pm.newQuery(Person.class);  // query
by the interface
                        Person person = (Person)query.execute();

                        assert person instanceof MyPerson == true;

This does not work, however (at least with JPOX).  My instanceof  
assertion at bottom fails, because person is actually a type  
generated by the implementation (PersonImpl in the case of JPOX).   
While I understand that this class generation approach may have some  
uses, I'm actually dealing with I believe is a much simpler use case  
that doesn't seem to be supported:  I simply want to be able to  
persist an instance of a concrete type and subsequently query for  
that object by it's interface.

Am I missing something?  Note that I'm not looking for any JPOX- 
specific tips here; just some guidance on usage per the spec.


- Chris

Chris Beams

Reply via email to