java - Querying a nullable @OneToOne relationship with JPA -
i have entity1 , entity2. have onetoone nullable relationship.
@entity class entity1 { @id @column(name = "id") private long id; @onetoone(fetch = fetchtype.lazy, cascade = cascadetype.all, mappedby = "entity2") @joincolumn(nullable = true) private entity2 entity2; ... } how can query entity1 objects has null entity2?
because if do:
select e entity1 e e.entity2 null jpa engine join between 2 tables , put useless clausule (where entity_id = null). resuming, executes useless native sql. how can
current solution:
reading openjpa documentation, found native queries should used workaround jpa limitations. can easy using native query , i'm doing it, avoid use it.
you can run jpql query:
select e1 entity1 e1 left join e1.entity2 e2 e2 null the left join looking for.
Comments
Post a Comment