db-jdo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: Query by interface
Date Sat, 01 Sep 2007 13:26:42 GMT
Hi Chris,

I guess you mapped both Person and MyPerson to the same tables in the  
database (and didn't add a discriminator column to distinguish Person  
from MyPerson). So the implementation thinks you want a generated  
Person to be constructed from the database rows.

The discussion of persistent interfaces has not been translated into  
spec-language, and this is one of several use cases that need to be  
discussed.

But for now, what if you don't map Person to the database?

Craig

On Sep 1, 2007, at 12:14 AM, cbeams wrote:

>
> As a user, here's what I would expect to work:
>
>
> 	@PersistenceCapable(table="person")
> 	public interface Person {}
>
> 	@PersistenceCapable(table="person")
> 	public class MyPerson implements Person {}
>
>
> 	public class Main {
> 		public static void main(String... args) {
> 			PersistenceManagerFactory pmf =  
> JDOHelper.getPersistenceManagerFactory("pmf.properties");
> 			PersistenceManager pm = pmf.getPersistenceManager();
> 			
> 			pm.currentTransaction().begin();
> 			pm.makePersistent(new MyPerson());  // persist the concrete type
> 			pm.currentTransaction().commit();
>
> 			Query query = pm.newQuery(Person.class);  // query by the interface
> 			query.setUnique(true);
> 			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.
>
> Thanks,
>
> - Chris
>
> Chris Beams
>
>
>
>
>
>
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Mime
View raw message