0

I have a some entities inheriting an AbstractEntity like below.

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class AbstractEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    private int id;

    @Column(insertable = false, updatable = false)
    private String dtype;

    public String getDtype() {
        return dtype;
    }
}

Then I persist some entity that extends AbstractEntity.

ConcreteEntity concreteEntity = new ConcreteEntity();
em.persist(concreteEntity);

If then in some other ejb fetch this entity using

someEntity = query.getResultList().get(0);        

the instance returned will have dtype == null until

em.refresh(someEntity);

I guess this is because the entity manager returns a cached instance that doesnt know which dtype was inserted on em.persist().

But my question is how can I have the query return instances where dtype is set?

Im using glassfish 3.1.2.2 (default jpa provider and the included javadb)

Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74

1 Answers1

1

Why do you even need it? dtype is an internal implementation detail needed by ORM. You can simply use Java type to distinguish between subclasses. E.g. in Facelets context you can try .getClass().getSimpleName():

#{entity.class.simpleName == 'ConcreteEntity'}

Not entirely cleaner, but works.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674