users@glassfish.java.net

RE: EJBQL Exception

From: Shevland, Joe <joe.shevland_at_capgemini.com>
Date: Tue, 1 May 2007 12:31:48 +1000

> > I'm a Java Persistence newbie having a massive problem spotting the
> > error that is triggering an Unknown state or association field
> > exception.
>
> The rest of the code for Seller and its annotations might
> make it a bit easier... have you annotated selcatId getter
> with a @Column?
>
> I don't think its that (and I'm not sure if JPA enforces
> having a relationship defined when you use a join in the
> EJBQL like that), but I'd probably tackle it a different way
> and put a @ManyToOne relationship on Seller back to SelCat,
> and in the query just use: "select s from Seller s where
> s.category = :pugdog" or along those lines, keeps the queries
> simpler and less fragile.

Forgot to paste, I think this is right for your case (or you could do it
the other way, a OneToMany on SelCat, or both):

  @Entity public class Seller ... {
    ...
    @ManyToOne
    @JoinColumn(name="selcatID")
    private SelCat category;
    ...
  }

(that's just using the property, I tend to prefer using the
getter/setter but that's briefer).

QL:

  select slr
  from Seller slr
  where slr.category = :category
    and slr.disabled = false
    and slr.category.someProperty = :someRestriction ...

This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.