I would appreciate if somebody helps to solve my problem.
Here is the thing. I use jakarta-persistence-api-3.1.0.
There is the super class:
@MappedSuperclass
public abstract class AbstractStatus{
...here are business fields...
}
There are two children:
@Entity
public Status_A extends AbstractStatus{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator=STATUS_A_GENERATOR)
@SequenceGenerator
private long id;
}
@Entity
public Status_B extends AbstractStatus{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator=STATUS_B_GENERATOR)
@SequenceGenerator
private long id;
}
So, each <? extends AbstractStatus> Entity has it’s own Id with specific generator.
There is abstract superclass for AbstractProduct that has AbstractStatus joined:
@MappedSuperclass
public abstract class AbstractProduct<ST extends AbstractStatus>{
@ManyToOne
@JoinColumn(name=“productStatusId”)
pivate ST status;
}
And there is specific Product_A with NamedQuery on it:
@Entity
@NamedQuery(name = “Query”, query = “SELECT product
FROM Product_A product
WHERE product.status.id = 42”)
public class Product_A extends AbstractProduct<Status_A>{
}
And the problem here that it cannot resolve .id field of the product.status because it doesn’t know what the implementation of the AbstractStatus to look at, seems, it cannot resolve generic type on compile time.
If run such code in a test it will fail with
Cannot resolve attribute ‘id’ of ‘AbstractStatus’ due to the attribute being declared in multiple subtypes [Status_A, Status_B]