0
@Entity
@Table(name="property")
@NamedQuery(name="Property.findAll", query="SELECT p FROM Property p")
public class Property implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "property_seq")
    @SequenceGenerator(name = "property_seq", allocationSize = 1, sequenceName = "s_property")
    @Column(name="property_id", unique=true, nullable=false, precision=10)
    private long propertyId;

    @Column(length=4000)
    private String description;

    //bi-directional many-to-one association to City
    @ManyToOne
    @JoinColumn(name="city_id")
    private City city;

    //bi-directional many-to-one association to PropertyAmenity
    @OneToMany(mappedBy="property", cascade = CascadeType.ALL)
    private List<PropertyAmenity> propertyAmenities;

@Entity
@Table(name="city")
@NamedQuery(name="City.findAll", query="SELECT c FROM City c")
public class City implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="city_id", unique=true, nullable=false, precision=10)
    private long cityId;

    @Column(name="city_name", nullable=false, length=50)
    private String cityName;
    @JsonIgnore
    @Column(name="last_updated_by", length=50)
    private String lastUpdatedBy;
    @JsonIgnore
    @CreationTimestamp
    @Column(name="last_updated_date")
    private Timestamp lastUpdatedDate;

    //bi-directional many-to-one association to State
    @ManyToOne
    @JoinColumn(name="state_id", nullable=false)
    private State state;

@Entity
@Table(name="state")
@NamedQuery(name="State.findAll", query="SELECT s FROM State s")
public class State implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="state_id", unique=true, nullable=false, precision=10)
    private long stateId;

    @Column(name="country_name", nullable=false, length=50)
    private String countryName;
    @JsonIgnore
    @Column(name="last_updated_by", length=50)
    private String lastUpdatedBy;
    
    @CreationTimestamp
    @JsonIgnore
    @Column(name="last_updated_date")
    private Timestamp lastUpdatedDate;

    @Column(name="state_name", nullable=false, length=50)
    private String stateName;

@Entity
@Table(name="property_amenities")
@NamedQuery(name="PropertyAmenity.findAll", query="SELECT p FROM PropertyAmenity p")
public class PropertyAmenity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "property_amenity")
    @SequenceGenerator(name = "property_amenity", allocationSize = 1, sequenceName = "s_property_amenities")
    @Column(name="property_amenities_id", unique=true, nullable=false, precision=10)
    private long propertyAmenitiesId;

    @Column(name="avilable_flag", nullable=false)
    private Boolean avilableFlag;

    @Column(name="last_updated_by", length=50)
    private String lastUpdatedBy;

    @Column(name="last_updated_date")
    private Timestamp lastUpdatedDate;

    @Column(name="master_amenity_type", nullable=false, length=10)
    private String masterAmenityType;

    //bi-directional many-to-one association to Property
    @ManyToOne
    @JoinColumn(name="property_id")
    private Property property;

}

public interface PropertyProjection {

        String getDescription() ;
        CityProjection getCity();
        List<PropertyAmenityProjection> getPropertyAmenities(); 
        
    public interface CityProjection {

            String getCityName() ;
            StateProjection getState() ;
    }
    
    public interface StateProjection {

        String getCountryName() ;
        String getStateName() ;
    }
            

    public interface PropertyAmenityProjection {
        String getMasterAmenityType() ;
        String getAvilableFlag() ;
    }   

}


@Repository
public interface PropertySearchRepository  extends JpaRepository<Property,Long> {

    
    @Query(value = **"select p.description,c.city_name,s.country_name,s.state_name,pa.avilable_flag,pa.master_amenity_type from property p,city c,state s,property_amenities pa where p.city_id=c.city_id "
            + "and c.state_id=s.state_id and p.property_id = pa.property_id"**, nativeQuery = true)
     public List<Property> getAllProperties();

}

在我们的项目中,需要从物业、城市、州和物业设施表中获取数据。为此,我编写了上面提到的本地 sql 查询 Respository。此查询数据需要绑定到PropertyProjection对象。绑定数据时,服务器日志中出现结果集错误。您能否告诉我,如何为上述复杂投影绑定数据。

4

0 回答 0