JPA 2 — Using @ElementCollection in CriteriaQuery

后端 未结 2 2094
醉梦人生
醉梦人生 2020-12-15 13:15
    @Entity
    public class Person {

        @ElementCollection
        private List locations;

        [...]

    }

    @Embeddable
    public c         


        
2条回答
  •  失恋的感觉
    2020-12-15 13:22

    The key phrase in Pascal's reply is

    the target objects cannot be queried, persisted, merged independently of their parent object

    As you are dependent on the parent object, you should be able to do this using something like ...

    SELECT p FROM PERSON, IN (p.locations) WHERE p.id = ?1 AND locations = ?2

    (Based on the reply at Execute "MEMBER OF" query against 'ElementCollection' Map fields in JP-QL (JPA 2.0) - which is actually a Map @ElementCollection which was what I was looking for an answer to!)

提交回复
热议问题