开发者

Legacy database mapping issue with JPA 1.0

开发者 https://www.devze.com 2023-03-19 15:52 出处:网络
I have a problem with mapping a legacy database with JPA 1.0. The database is stored denormalized for data-mining purposes. I condensed it to a simple example that hopefully clarifies the issue. Assum

I have a problem with mapping a legacy database with JPA 1.0. The database is stored denormalized for data-mining purposes. I condensed it to a simple example that hopefully clarifies the issue. Assume I have the following two tables:

Table ITEMS
  PKEY  GROUPID  NAME
  1     1        'AX'
  2     1        'AY'
  3     2        'BX'
  4     2        'BY'

Table XENTITY
  PKEY  ITEMGROUPID  NAME
  1     1            'E1'
  2     1            'E2'
  3     2            'E3'
开发者_StackOverflow社区

What I basically want to accomplish is accessing all ITEMs from an XENTITY that have the GROUPID that is stored in the XENTITY's ITEMGROUPID column. Java-class-wise this should look like the following snippet.

class Item {
}

class XEntity {
    public Set<Item> getItems();
}

So for the XENTITIEs 'E1','E2' I whould get the ITEMs 'AX', 'AY' and for 'E3' I would get 'BX','BY'.

I am uncertain about how to map such a situation with JPA. Several trial-and-error attempts have unfortunately left me very empty-handed. I whould greatly appreciate any help in this regard.

Thanks in advance,

Alex


You have a very uncommon many-to-many association here, and I doubt you can get the information you want with a mapping. You should probably use a specific query to get what you want:

select item from Item item where item.groupId = :groupId
0

精彩评论

暂无评论...
验证码 换一张
取 消