Hibernate @Where Q.

时间:2012-12-12 19:56:25

标签: hibernate annotations

我想将Train.fares映射到Fares类,但只显示当前有效的票价(在有效/到期日期窗口内)。在费用的@Where注释中,如何指定effDateexpDate引用Fare.effDateFare.expDate

@Entity
@Table(name = "TRAIN")
@Configurable
public class Train {

    @Id
    private String id;

    @Column
    private Date ddate;

    @Column
    private String company;

    @Column (name = "NBR")
    private String trainNbr;

    @OneToMany(mappedBy = "flight", fetch = FetchType.LAZY)
    @Id
    private List<Fare> Fares;

    ...setters & getters
}


@Entity
@Table(name = "FARE")    
public class Fare {

    @Id
    private Long id;

    @Column 
    private String company;

    @Column (name = "NBR")
    private string trainNbr;

    @Column
    private Date effDate;

    @Column 
    private Date expDate;

    @ManyToOne
    @JoinColumns({
        @JoinColumn(name = "COMP", referencedColumnName = "COMP", insertable = false, updatable = false),
        @JoinColumn(name = "NBR", referencedColumnName = "NBR", insertable = false, updatable = false)
    })
    @Where(clause = "SELECT t from TRAIN as t where t.ddate >= effDate AND t.ddate <= expDate")
    private Train train;

    ...setters & getters
}

0 个答案:

没有答案