Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » query with JoinTable
query with JoinTable [message #553198] Mon, 16 August 2010 16:28 Go to next message
Lars Fischer is currently offline Lars FischerFriend
Messages: 105
Registered: July 2009
Senior Member
Hello,

I need some help with a JPA query and would be happy, if someone could
give me a hint, how to solve this:

I have an entity "Receipt" which holds a map of "Item" entities. The
map-key is an integer, which represents the order of the contained
items. My mapping looks like this:

@ManyToMany()
@JoinTable(name = "RECEIPT_ITEM", joinColumns = @JoinColumn(name =
"RECEIPT_ID"), inverseJoinColumns = @JoinColumn(name = "ITEM_ID"))
@MapKeyColumn(name = "POSITION", table = "RECEIPT_ITEM")
private Map<Integer, Item> items;

Item has a mapped unique string property "name" and no knowledge of
Receipts.

Now I need a query returning all Receipts, which are connected to an
Item with a given name.

Do I have to join Receipt and Item or can I query about the contents of
the "items" map?

Regards,
Lars
Re: query with JoinTable [message #553199 is a reply to message #553198] Mon, 16 August 2010 16:30 Go to previous messageGo to next message
Lars Fischer is currently offline Lars FischerFriend
Messages: 105
Registered: July 2009
Senior Member
On 16.08.2010 18:28, Lars Fischer wrote:
> I need some help with a JPA query and would be happy, if someone could
> give me a hint, how to solve this:
>
> I have an entity "Receipt" which holds a map of "Item" entities. The
> map-key is an integer, which represents the order of the contained
> items. My mapping looks like this:
>
> @ManyToMany()
> @JoinTable(name = "RECEIPT_ITEM", joinColumns = @JoinColumn(name =
> "RECEIPT_ID"), inverseJoinColumns = @JoinColumn(name = "ITEM_ID"))
> @MapKeyColumn(name = "POSITION", table = "RECEIPT_ITEM")
> private Map<Integer, Item> items;
>
> Item has a mapped unique string property "name" and no knowledge of
> Receipts.
>
> Now I need a query returning all Receipts, which are connected to an
> Item with a given name.
>
> Do I have to join Receipt and Item or can I query about the contents of
> the "items" map?

Additional info:
- EclipseLink 2.1.0 (JPA 2.0)

Regards,
Lars
Re: query with JoinTable [message #553203 is a reply to message #553199] Mon, 16 August 2010 16:44 Go to previous message
Lars Fischer is currently offline Lars FischerFriend
Messages: 105
Registered: July 2009
Senior Member
Looks like this is working fine:

"select r from Receipt r, Item i where i.name = :iname and i member of
r.items"

Regards,
Lars

Note to me: don't soliloquize ;)
Previous Topic:An unexpected error > EXCEPTION_ACCESS_VIOLATION
Next Topic:persisting object with JPA results in id missmatch (db id != java object id)
Goto Forum:
  


Current Time: Sun Nov 23 07:49:57 GMT 2014

Powered by FUDForum. Page generated in 0.15070 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software