按日期范围进行Hibernate一对多映射?

时间:2012-12-13 20:05:59

标签: java hibernate

我想将Train.trainFares从transient更改为映射到TrainFare类。但是,我想将TrainFares限制为对Train.ddate有效的那些。我该怎么做呢?

我找到了一个Hibernate Jira issue,我认为这可能是我问题的根源。还有其他人遇到过这个问题吗?你找到了解决方法吗?

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

    @EmbeddedId
    private TrainPK id;

    @Column
    private String trainType;

    @Transient
    private List<TrainFare> trainFares;

    @Embeddable
    public static class TrainPK {

        @Column
        private String company;

        @Column
        private Date departDate;

        @Column 
        private String trainNumber;
    }

    ... setters & getters
}

@Entity
@Table(name = "SEATRATE")
public class SeatRate { 

    @EmbeddedId
    private SeatRatePK id;

    @Column
    private Date expiryDate; 

    @Column
    private String trainNumber;

    @Embeddable
    public static class SeatRatePK { 

        @Column
        private String company

        @Column 
        private Date effectiveDate;

    }

    ... setters & getters
}

0 个答案:

没有答案