I have a class annotated like this:
Code:
@Entity
@Table(name = "ncc_failure")
public class NccFailure
{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_STORE")
private long id;
@CollectionOfElements( fetch = FetchType.EAGER)
@JoinTable(
name = "ncc_failure_subnet_link",
joinColumns = @JoinColumn(name = "ncc_failure__id")
)
@Column( name="ip_subnet_id", nullable = false)
private final Set<String> subnetIds = new HashSet<>();
@AccessType("property")
@Lob
@Column(name = "summary")
private String summary;
@AccessType("property")
@Lob
@Column(name = "file_lines_data")
private String fileLinesData;
}
After Hibernate generates the schema, I have one table (ncc_failure) with 3 fields: id, summary and property. And then there's a link table (ncc_failure_subnet_link) with 2 fields: ncc_failure__id and ip_subnet__id. The idea is that one NccFailure object can contains many subnetId's.
What I want to do is to update the summary of all the NccFailure objects whose subnetIds contains at least one from a fixed list. In plain SQL I'll write it as:
Code:
update ncc_failure set summary='new summary' where id in
(select distinct id from ncc_failure as failure inner join ncc_failure_subnet_link as link on failure.id = link.ncc_failure__id
where link.ip_subnet__id in ('id1', 'id2', 'id3', 'id4'));
However I don't know how to write it properly with HQL. All my attempts have failed so far. I would imagine it's something like this:
Code:
update NccFailure set summary='new summary' where id in (select id from NccFailure as failure where any elements(failure.subnetIds) in ('id1', 'id2', 'id3', 'id4'));
But this fails with
"syntax error at or near "any"".I've also tried some other variations of "any" and "elements" and the alias but to no avail. There's always an error. What did I miss?
(The reason I put the title as "HQL join" is because I know if subnetIds is a collection of non-primitive objects, I can write a join with the class of subnetIds and the HQL query will be good. But in this case it's a primitive type collection and I don't know how to do a join, or if one is even necessary. I assume it's implicit, but I can't seem to make it work so far. If it's not implicit, then I don't know how to write that join, hence the question).
Thanks.