JPA中的集合查询示例

1、VisitInfo模型 view plaincopy to clipboardprint? @Entity @Table(name = System_VisitInfo) @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class VisitInfo implements Serializable { private static final long serialVersionUID = 287
<script src="/plus/ad_js.php?aid=5"></script>

1、VisitInfo模型

    view plaincopy to clipboardprint?
    @Entity

    @Table(name = "System_VisitInfo")

    @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

    public class VisitInfo implements Serializable {

        private static final long serialVersionUID = 2877662856939429897L;

 

        @Id

        @GeneratedValue(strategy = GenerationType.TABLE)

        private Long id;

 

        private Date vdate;

 

        @Column(length = 200)

        private String fromUrl;

 

        @Column(length = 200)

        private String url;

 

        @Column(length = 50)

        private String ip;

 

        private Integer status;

 

        @Column(length=1000)

        private String remark;

 

        @ManyToMany

        private List<SystemVisitDir> dirs=new java.util.ArrayList<SystemVisitDir>();

        public Long getId() {

            return id;

        }

    //setter及getter

    }

    @Entity

    @Table(name = "System_VisitInfo")

    @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

    public class VisitInfo implements Serializable {

     private static final long serialVersionUID = 2877662856939429897L;

 

     @Id

     @GeneratedValue(strategy = GenerationType.TABLE)

     private Long id;

 

     private Date vdate;

 

     @Column(length = 200)

     private String fromUrl;

 

     @Column(length = 200)

     private String url;

 

     @Column(length = 50)

     private String ip;

 

     private Integer status;

 

     @Column(length=1000)

     private String remark;

 

     @ManyToMany

     private List<SystemVisitDir> dirs=new java.util.ArrayList<SystemVisitDir>();

     public Long getId() {

      return id;

     }

    //setter及getter

    }view plaincopy to clipboardprint?
    <STRONG>2、SystemVisitDir 模型</STRONG>

2、SystemVisitDir 模型view plaincopy to clipboardprint? PRE class=java name=code @Entity @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @FormPO(inject = title,url,parent,sequence) pub
<script src="/plus/ad_js.php?aid=5"></script>

2、SystemVisitDir 模型view plaincopy to clipboardprint?
    <PRE class=java name="code">
    @Entity

    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

    @FormPO(inject = "title,url,parent,sequence")

    public class SystemVisitDir implements Serializable, IJsonObject {

        private static final long serialVersionUID = -6636698603262819988L;

        @Id

        @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.TABLE)

        private Long id;

 

        @Column(length = 20)

        @Field(validators = { @Validator(name = "string", value = "blank;min:2;max:20", required = true) })

        private String title;// 栏目名称

 

        @Column(length =500)

        @Field(validators = { @Validator(name = "url", required = true) })

        private String url;// 栏目url

 

        private Long num = 0l;// 访问量

 

        private Date lastVisitTime;// 最后一次访问时间

 

        private Integer sequence = 1;// 排序

 

        @javax.persistence.ManyToOne(fetch = FetchType.EAGER)

        @POLoad(name = "parentId")

        private SystemVisitDir parent;// 父级目录

 

        private Integer status = 0;

 

        @OneToMany(mappedBy = "parent")

        @OrderBy("sequence")

        private List<SystemVisitDir> children = new java.util.ArrayList<SystemVisitDir>();// 子目录

 

    //getter及setter

    }

    </PRE>

    view plaincopy to clipboardprint?  @Entity    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
     @FormPO(inject = "title,url,parent,sequence")
     public class SystemVisitDir implements Serializable, IJsonObject 
{
         private static final long serialVersionUID = -6636698603262819988L;
         @Id
        @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.TABLE)
         private Long id;
             @Column(length = 20)
         @Field(validators = { @Validator(name = "string", value = "blank;min:2;max:20", required = true) })
         private String title;// 栏目名称
             @Column(length =500)
         @Field(validators = { @Validator(name = "url", required = true) })
         private String url;// 栏目url
             private Long num = 0l;// 访问量
             private Date lastVisitTime;// 最后一次访问时间
             private Integer sequence = 1;// 排序
             @javax.persistence.ManyToOne(fetch = FetchType.EAGER)
         @POLoad(name = "parentId")
         private SystemVisitDir parent;// 父级目录
             private Integer status = 0;
             @OneToMany(mappedBy = "parent")
         @OrderBy("sequence")
         private List<SystemVisitDir> children = new java.util.ArrayList<SystemVisitDir>();// 子目录
         //getter及setter
     }

@Entity @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @FormPO(inject = title,url,parent,sequence) public class SystemVisitDir implements Serializable, IJsonObject { private static fin
<script src="/plus/ad_js.php?aid=5"></script>

@Entity

    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

    @FormPO(inject = "title,url,parent,sequence")

    public class SystemVisitDir implements Serializable, IJsonObject {

     private static final long serialVersionUID = -6636698603262819988L;

     @Id

     @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.TABLE)

     private Long id;

 

     @Column(length = 20)

     @Field(validators = { @Validator(name = "string", value = "blank;min:2;max:20", required = true) })

     private String title;// 栏目名称

 

     @Column(length =500)

     @Field(validators = { @Validator(name = "url", required = true) })

     private String url;// 栏目url

 

     private Long num = 0l;// 访问量

 

     private Date lastVisitTime;// 最后一次访问时间

 

     private Integer sequence = 1;// 排序

 

     @javax.persistence.ManyToOne(fetch = FetchType.EAGER)

     @POLoad(name = "parentId")

     private SystemVisitDir parent;// 父级目录

 

     private Integer status = 0;

 

     @OneToMany(mappedBy = "parent")

     @OrderBy("sequence")

     private List<SystemVisitDir> children = new java.util.ArrayList<SystemVisitDir>();// 子目录

 

    //getter及setter

    }

 

 

    3、集合查询

    集合查询主要涉及到一些关键字,主要是EMPTY及MEMBER OF。下面的例子查询某一个目录里面的VisitInfo

    public Page doListVisit(WebForm form, Module module)
{
   QueryObject qo = form.toPo(QueryObject.class);
   String id = CommUtil.null2String(form.get("parentId"));
   if (!"".equals(id))
{
    SystemVisitDir parent = this.service.getVisitDir(new Long(id));
    qo.addQuery("(?  MEMBER OF obj.dirs)",new Object[]{parent});
   }
   IPageList pageList = service.queryVisistInfo(qo);
   form.jsonResult(pageList);   return Page.JSONPage;
  }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值