-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @ManyToAny and in elements() throws SQLException
PostPosted: Wed May 20, 2009 9:20 pm 
Newbie

Joined: Wed May 20, 2009 9:15 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.