xrdty
xrdty

Reputation: 886

Non persistent superclass with persistent subclass

What happens when I persist this subclass? Are the variables a and b available when I'd query the database for the Subclass object? How can I persist a and b?

public Superclass {

    private int a;
    private Obj b;

    // ... 
}

@Entity
public Subclass extends Superclass{
    @id int x;

    public Subclass(int a, Obj b, int x){
        super(a, b);
    }
}

Upvotes: 1

Views: 227

Answers (1)

Mark Sholund
Mark Sholund

Reputation: 1312

a and b will not be persisted.

From https://docs.oracle.com/javaee/6/tutorial/doc/bnbqn.html

Non-Entity Superclasses

Entities may have non-entity superclasses, and these superclasses can be either abstract or concrete. The state of non-entity superclasses is nonpersistent, and any state inherited from the non-entity superclass by an entity class is nonpersistent. Non-entity superclasses may not be used in EntityManager or Query operations. Any mapping or relationship annotations in non-entity superclasses are ignored.

Upvotes: 2

Related Questions