More experimentation.
(1) Shifting to a NamedQuery did not change the behavior. (Somehow I find that
comforting.)
(2) Calling refresh on the entity did not cause the fields to be loaded.
B b = query.getSingleResult();
b = em.refresh(b);
(3) Calling find using the object ID did trigger a reload.
B b = query.getSingleResult();
b = em.find(A.class, b.getId());
This third approach is a potential workaround for the short term.
On Nov 12, 2010, at 12:49 AM, No1UNo [via OpenJPA] wrote:
> In OpenJPA 2.0.1, I define a native query which returns the base class for a
> group of inherited classes.
>
> Query query = em.createNativeQuery("...", A.class);
>
> The inherited classes are simple and have the form:
>
> @Entity
> @Inheritance(strategy=InheritanceType.JOINED)
> @DiscriminatorColumn(name="class_type",
> discriminatorType=DiscriminatorType.INTEGER)
> public abstract class A {
> // Defines an ID and at least one persistent field.
> }
>
> class B extends A implements Serializable {
> ...
> private String details;
> public String getDetails() { return details; }
> public void setDetails(String details) { this.details =
> details; }
> ...
> }
>
> My expectation is that this query should return an instance of B with any new
> fields resolved automatically (i.e. details should be non-NULL). Instead I
> am getting an instance of B but with only the fields defined by A being
> initialized! Am I crazy or is something broken?
>
> -=- Jerry
>
> View message @
> http://openjpa.208410.n2.nabble.com/Do-native-queries-respect-inheritance-tp5731353p5731353.html
>
> To start a new topic under OpenJPA Users, email
> [email protected]
> To unsubscribe from OpenJPA Users, click here.
>
--
View this message in context:
http://openjpa.208410.n2.nabble.com/Do-native-queries-respect-inheritance-tp5731353p5731380.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.