How to do Grouping using JPA annotation with mapping given field

Posted by hemal on Stack Overflow See other posts from Stack Overflow or by hemal
Published on 2010-03-16T11:11:47Z Indexed on 2010/03/16 11:16 UTC
Read the original article Hit count: 411

Filed under:
|
|

I am using JPA Annotation mapping with the table given below, but having problem that i am doing mapping on same table but on diffrent field given

ProductImpl.java

@Entity @Table(name = "Product")

public class ProductImpl extends SimpleTagGroup implements Product {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id = -1;

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "ProductTagMapping", joinColumns =@JoinColumn(name = "productId"), inverseJoinColumns =@JoinColumn(name = "tagId"))    
private List<SimpleTag> tags;

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "ProductTagMapping", joinColumns =@JoinColumn(name = "productId"), inverseJoinColumns =@JoinColumn(name = "tagId"))
private List<SimpleTag> licenses;

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "ProductTagMapping", joinColumns =@JoinColumn(name = "productId"), inverseJoinColumns =@JoinColumn(name = "tagId"))
private List<SimpleTag> os;

I want to get values like windows and linux in os , GPLv2 and GPLv3 in licenses ,so we are using TagGroup table . but here i got all tagValues in each of the os,licenses and tag fileds,so how could i do group by or some other things with JPA.

and ProductTagMapping is the mapping table between Tag and TagGroup

TagGroup Table

ID   TAGGROUPNAME  

1 PRODUCTTYPE
2 LICENSE
3 TAGS
4 OS

SimpleTag

ID   TAGVALUE  

1 Application
2 Framework
3 Apache2
4 GPLv2
5 GPLv3
6 learning
7 Linux
8 Windows
9 mature

© Stack Overflow or respective owner

Related posts about jpa

Related posts about spring-mvc