hibernate注解方式实现联合查询

一、entity

package com.dorlat.entity;  
 
import java.io.Serializable;  
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;

@Entity
@Table(name="exchange_details")
public class ExchangeDetails implements Serializable{

    private Long id;
    private  Long customerId;  
    private  Long orderId;  
    private  Double castIntegral;  
    private  Integer status;  
    private  Integer type;  
    private  java.util.Date createTime;  
    private String goodsName;
    private Integer orderStatus;
    
    

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id",unique=true,nullable=false)
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }  
  
    public void setCustomerId(Long customerId){  
       this.customerId=customerId;  
    }
      
    @Column(name="customer_id",nullable=true,length=2147483647)  
    public Long getCustomerId(){  
       return this.customerId;  
    }  
  
    public void setOrderId(Long orderId){  
       this.orderId=orderId;  
    }
      
    @Column(name="order_id",nullable=true,length=2147483647)  
    public Long getOrderId(){  
       return this.orderId;  
    }  
  
    public void setCastIntegral(Double castIntegral){  
       this.castIntegral=castIntegral;  
    }
      
    @Column(name="cast_integral",nullable=true,length=2147483647)  
    public Double getCastIntegral(){  
       return this.castIntegral;  
    }  
  
    public void setStatus(Integer status){  
       this.status=status;  
    }
      
    @Column(name="status",nullable=true,length=2147483647)  
    public Integer getStatus(){  
       return this.status;  
    }  
  
    public void setType(Integer type){  
       this.type=type;  
    }
      
    @Column(name="type",nullable=true,length=2147483647)  
    public Integer getType(){  
       return this.type;  
    }  
  
    public void setCreateTime(java.util.Date createTime){  
       this.createTime=createTime;  
    }
      
    @Column(name="create_time",nullable=true,length=2147483647)
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
    public java.util.Date getCreateTime(){  
       return this.createTime;  
    }  

    

    
    

    public ExchangeDetails(Long id, Long customerId, Long orderId,
            Double castIntegral, Integer status, Integer type, Date createTime,
            String goodsName, Integer orderStatus) {
        super();
        this.id = id;
        this.customerId = customerId;
        this.orderId = orderId;
        this.castIntegral = castIntegral;
        this.status = status;
        this.type = type;
        this.createTime = createTime;
        this.goodsName = goodsName;
        this.orderStatus = orderStatus;
    }

    public ExchangeDetails() {
        super();
    }
    
    @Override
    public String toString() {
        return "ExchangeDetails [id=" + id + ", customerId=" + customerId
                + ", orderId=" + orderId + ", castIntegral=" + castIntegral
                + ", status=" + status + ", type=" + type + ", createTime="
                + createTime + ", goodsName=" + goodsName + ", orderStatus="
                + orderStatus + "]";
    }

    @Transient
    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }
    @Transient
    public Integer getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(Integer orderStatus) {
        this.orderStatus = orderStatus;
    }

    
}

二、services实现类

    @Override
    public Map<String, Object> getAll(int start, int limit,
            ExchangeDetails entity) {
        Map<String, Object> map =new HashMap<String, Object>();

        List<ExchangeDetails> listByPage = exchangeDetailsDao
                .listByPage(
         "select new ExchangeDetails(a.id, a.customerId, a.orderId, a.castIntegral, a.status," +
                 "a.type, a.createTime, c.goodsName, b.status) from ExchangeDetails a, CustomerOrder b , GoodsManage c where " +
                 " a.orderId = b.id AND b.goodsId = c.id"
                + " and a.customerId ='"+entity.getCustomerId() +"'"
            + " ", start, limit);
        map.clear();
        map.put("items", listByPage);
        map.put("total", listByPage.size());
    
        return map;
    }

 

posted @ 2014-12-11 10:52  x1ao风  阅读(534)  评论(0)    收藏  举报