Announcement Announcement Module
Collapse
No announcement yet.
in elements() with param that has a composite key.. - help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • in elements() with param that has a composite key.. - help

    SelectedTarget and SelectedSource are associated entities both with composite PK's


    @Entity
    @EqualsAndHashCode(includes=['activationUUID','target'])
    @IdClass(SelectedTargetPK.class)
    class SelectedTarget {


    @Id
    UUID activationUUID

    @Id
    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "targetId")
    @NotNull
    Target target

    int targetTypeId

    @NotEmpty
    @OneToMany(fetch=FetchType.EAGER, cascade= [CascadeType.ALL])
    @JoinTable(
    joinColumns =
    [
    @JoinColumn(name="selected_target_activationuuid") ,
    @JoinColumn(name="selected_target_target_id")
    ],
    inverseJoinColumns =
    [
    @JoinColumn(name="selected_source_activationuuid") ,
    @JoinColumn(name="selected_source_source_type"),
    @JoinColumn(name="selected_source_source_id"),

    ]
    )
    Set<SelectedSource> sources = [] as Set

    int primarySourceId

    }

    @EqualsAndHashCode
    class SelectedTargetPK implements Serializable{
    UUID activationUUID
    Target target
    }





    @Entity
    @EqualsAndHashCode(includes=['activationUUID','sourceType','sourceId'])
    @IdClass(SelectedSourcePK.class)
    class SelectedSource {

    @Id
    UUID activationUUID

    @Id
    @Enumerated(EnumType.ORDINAL)
    SourceType sourceType

    @Id
    long sourceId

    }




    @EqualsAndHashCode
    class SelectedSourcePK implements Serializable{

    UUID activationUUID
    SourceType sourceType
    long sourceId

    }


    The following query on my spring data repository wont work though, it complains about column count, why ?



    @Query("select st from SelectedTarget st where :selectedSource in elements(st.sources)")
    Page<SelectedTarget> findEffectivelySelectedTargetsForSelectedSource(@P aram("selectedSource") SelectedSource selectedSource, Pageable pageable)

  • #2
    solution..


    @Query("""SELECT st from SelectedTarget st JOIN st.sources s
    WHERE s.selectedSourcePK.activationUUID = :activationUUID AND s.selectedSourcePK.sourceType = :sourceType and s.selectedSourcePK.sourceId=:sourceId""")
    Page<SelectedTarget> findEffectivelySelectedTargetsForSelectedSource(
    @Param("activationUUID") UUID activationUUID, @Param("sourceType") SourceType sourceTypeId, @Param("sourceId") Long sourceId,
    Pageable pageable)

    Comment

    Working...
    X