Vaadin - JPAContainer过滤器加入ManyToMany关系

时间:2014-08-26 18:39:16

标签: java hibernate many-to-many vaadin jpacontainer

我在User和Context类之间有一个ManyToMany关系,在中间表中有一个额外的列。

Users.java

@Entity
@Table(name = "USERS")
public class Users {
    private Long user_id;
    private Long niu;
    private String nom;
    private String mail;
    private Set<UserContext> userContexts  = new HashSet<UserContext>(0);

Context.java

@Entity
@Table(name = "CONTEXT")
public class Context {
    private Long id;
    private String name;
    private Area area;
    private String code;
    private Set<UserContext> userContexts = new HashSet<UserContext>(0);

UserContext.java

@Entity
@Table(name = "USER_CTX")
@AssociationOverrides({
        @AssociationOverride(name = "pk.user",
            joinColumns = @JoinColumn(name = "USER_ID")),
        @AssociationOverride(name = "pk.context",
            joinColumns = @JoinColumn(name = "CTXT_ID")) })
public class UserContext implements Serializable{

    private static final long serialVersionUID = 1L;
    private UserContextID pk = new UserContextID();
    private String admin;

UserContextID.java

@Embeddable
public class UserContextID implements Serializable {

    private static final long serialVersionUID = -9120607274421816301L;
    private Users user;
    private Context context;

我有一个使用JPAContainer填充的表,

private JPAContainer<Users> persons =
    JPAContainerFactory.make(Users.class, PERSISTENCE_UNIT);

实际上它显示了所有用户(没有上下文过滤器),我想要的是使用这个ManyToMany关系过滤具体的上下文id,任何想法?我曾尝试使用JoinFilters,但我无法得到它,请帮助我!

提前致谢!

1 个答案:

答案 0 :(得分:0)

您可以使用过滤器,使用点表示法选择正确的子属性,例如

entityContainer.addContainerFilter(new Like("listOfAnotherEntity.type", "TYPE1"));