Consider code:
public class Transaction {
...
@OneToMany
@Fetch(FetchMode.SUBSELECT)
@LazyCollection(LazyCollectionOption.EXTRA)
@Where(clause = "entity=4")
@JoinColumn(name = "entity_id")
private List<Alert> alerts;
...
}
public class Alert {
...
@Any(metaColumn = @Column(name = "entity"), fetch = FetchType.LAZY)
@AnyMetaDef(
idType = "long",
metaType = "integer",
metaValues = {
@MetaValue(value = "4", targetEntity = Document.class),
@MetaValue(value = "9", targetEntity = Transaction.class)})
@JoinColumn(name = "entity_id", insertable = false, updatable = false)
private Object relatedObject;
...
}
produces wrong SQL on size retrieval operation:
select
count(id)
from
alerts
where
entity_id =?