使用java中的hibernate将mySQL存储过程映射到多个实体

使用java中的hibernate将mySQL存储过程映射到多个实体,java,hibernate,nhibernate-mapping,Java,Hibernate,Nhibernate Mapping,我在mysql数据库中有以下存储过程: create definer = root@localhost procedure GetAllAvailableTentsAndTimeSlots() BEGIN select *from tentslots left join timeslots t on t.PM = tentslots.timeslots_fk left join tents t2 on tentslots.tent_id_f

我在mysql数据库中有以下存储过程:

    create
    definer = root@localhost procedure GetAllAvailableTentsAndTimeSlots()
BEGIN
    select *from tentslots
        left join timeslots t on t.PM = tentslots.timeslots_fk
        left join tents t2 on tentslots.tent_id_fk = t2.tent_id
    where TENT_BOOKING_ID is null;
END;
我的实体是: 帐篷类

import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.*;

@Entity
@ApiModel
@Table(name = "tentslots")
public class Tentslots implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "TENT_SLOT_ID")
    @ApiModelProperty(hidden = true)
    private Long tentSlotId;

    @Column(name = "timeslots_fk")
    @ApiModelProperty(value = "The timeslot id")
    private Integer timeSlotIdFk;

    @Column(name = "tent_id_fk")
    @ApiModelProperty(value = "The tent id")
    private Integer tentIdFk;

    @Column(name = "TENT_BOOKING_ID")
    @ApiModelProperty(value = "The tent booking id")
    private Integer tentBookingId;

    public Long getTentSlotId() {
        return tentSlotId;
    }

    public void setTentSlotId(Long tentSlotId) {
        this.tentSlotId = tentSlotId;
    }


    public Integer getTimeSlotIdFk() {
        return timeSlotIdFk;
    }

    public void setTimeSlotIdFk(Integer slotId) {
        this.timeSlotIdFk = slotId;
    }


    public Integer getTentIdFk() {
        return tentIdFk;
    }

    public void setTentIdFk(Integer tentIdFk) {
        this.tentIdFk = tentIdFk;
    }


    public Integer getTentBookingId() {
        return tentBookingId;
    }

    public void setTentBookingId(Integer tentBookingId) {
        this.tentBookingId = tentBookingId;
    }
}
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;


import javax.persistence.*;

import java.util.Date;

    @Entity
    @ApiModel
    @Table(name = "timeslots")
    public class Timeslots {
    
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "PM")
        @ApiModelProperty(hidden = true)
        private Integer pm;
    
        @Column(name = "TIMESLOT")
        @ApiModelProperty(value = "The Latitude of a tent")
        private Date timeslot;
    
        public Integer getPm() {
            return pm;
        }
    
        public void setPm(Integer pm) {
            this.pm = pm;
        }
    
        public Date getTimeslot() {
            return timeslot;
        }
    
        public void setTimeslot(Date timeslot) {
            this.timeslot = timeslot;
        }
帐篷类

import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.*;

@Entity
@ApiModel
@Table(name = "tents")
public class Tent {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "tent_id")
    @ApiModelProperty(hidden = true)
    private Integer tentId;

    @Column(name = "LATITUDE")
    @ApiModelProperty(value = "The Latitude of a tent")
    private Long latitude;

    @Column(name = "LONGITUDE")
    @ApiModelProperty(value = "The longitude of a tent")
    private Long longitude;

    @Column(name = "FRIENDLY_NAME")
    private String friendlyName;

    @OneToMany (targetEntity = Tentslots.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "tent_id_fk", referencedColumnName = "tent_id")
    private List<Tentslots> tentslots;

    public int getTentId() {
            return tentId;
    }
   

    public void setTentId(int tentId) {
        this.tentId = tentId;
    }

    public Long getLatitude() {
        return latitude;
    }

    public void setLatitude(Long latitude) {
        this.latitude = latitude;
    }

    public Long getLongitude() {
        return longitude;
    }

    public void setLongitude(Long longitude) {
        this.longitude = longitude;
    }

    public String getFriendlyName() {
        return friendlyName;
    }

    public void setFriendlyName(String friendlyName) {
        this.friendlyName = friendlyName;
    }

    public List<Tentslots> getTentslots() {
        return tentslots;
    }

    public void setTentslots(List<Tentslots> tentslots) {
        this.tentslots = tentslots;
    }
}
我从TentslotsRepository.class调用存储过程

import com.stavros.camping.entity.Tentslots;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

import javax.transaction.Transactional;

public interface TentslotsRepository extends CrudRepository<Tentslots, Long> {

    List<Tentslots> findAllByTentBookingIdIsNull();

    List<Tentslots> findAllByTentSlotId(Integer slotId);

    List<Tentslots> findAllByTentSlotIdAndAndTentBookingIdIsNull(Integer slotId);

    List<Tentslots> findAllByTentSlotIdAndAndTentBookingIdIsNotNull(Integer slotId);

    @Procedure
    @Transactional
    void GetAllAvailableTentsAndTimeSlots();
}
import com.statvros.camping.entity.Tentslots;
导入org.springframework.data.jpa.repository.query.Procedure;
导入org.springframework.data.repository.crudepository;
导入java.util.List;
导入javax.transaction.Transactional;
公共接口TentslotsRepository扩展了Crudepository{
列出findAllByTentBookingIdIsNull();
列出FindAllBytes slotId(整数slotId);
列出FindAllBytes slotId和TentBookingIDisNLL(整数slotId);
列出FindAllBytes slotId和TentBookingIDisNotFull(整数slotId);
@程序
@交易的
void getAllAvailabletents和时隙();
}
我的问题是,如何将过程(3个联接表)返回的结果集映射到三个不同的实体对象中。我是否有可能或者应该创建一个新对象(投影)