How do I query for an object A with an @ManyToAny collection containing another object B?
My attempt below throws
SQLException: Operand should contain 1 column(s).
Code:
interface IProblemAssociated;
@Entity
class Problem { // A
[...]
ArrayList<IProblemAssociated> associated = new ArrayList<ProblemAssociated>();
@ManyToAny(
metaColumn = @Column( name = "property_type" ), fetch=FetchType.LAZY )
@AnyMetaDef(
idType = "long",
metaType = "string",
metaValues = {
@MetaValue( value = "ToolInvocation", targetEntity = ToolInvocation.class ),
[...]
}
)
@JoinTable( name = "Problem_ProblemAssociated", joinColumns = @JoinColumn( name = "problemAssociated_id" ),
inverseJoinColumns = @JoinColumn( name = "problem_id" ))
List<IProblemAssociated> getAssociated() {
return associated;
}
}
@Entity
class ToolInvocation {} //B
IProblemAssociated pa = <a ToolInvocation>;
Query q = s.createQuery("FROM Problem where :pa in elements(associated)");
q.setParameter("pa", pa);
return q.list(); // throws SQLException: Operand should contain 1 column(s)
query is:
Code:
SELECT problem0_.id AS id24_,
[...]
FROM problem problem0_
WHERE ? IN (SELECT associated1_.property_type,
associated1_.problem_id
FROM problem_problemassociated associated1_
WHERE problem0_.id = associated1_.problemassociated_id)
I'm trying to avoid having a separate join table for each of a dozen different types where I want to record 1 or more errors, and there are few cases that result in errors. Is there a better way to do this? I was using inheritance before from a base entity ProblemAssociated but the performance was terrible.
Thanks!
-c
BTW- this is Hibernate 3.3.1.GA and Hibernate Annotations 3.4.0.GA