Java 如何在hibernate注释中实现组件映射
您好,我正在尝试将我的hbm文件映射转换为hibernate注释,我在这里找到了类似于Java 如何在hibernate注释中实现组件映射,java,hibernate,hibernate-mapping,hibernate-annotations,Java,Hibernate,Hibernate Mapping,Hibernate Annotations,您好,我正在尝试将我的hbm文件映射转换为hibernate注释,我在这里找到了类似于 <component name="timeSlot" class="model.calendar.TimeSlot"> <property name="startTime" column="app_start_time" /> <property name="endTime" column="app_end_time" /> </component>
<component name="timeSlot" class="model.calendar.TimeSlot">
<property name="startTime" column="app_start_time" />
<property name="endTime" column="app_end_time" />
</component>
我的timeslot.java
modal看起来像
public class TimeSlot extends BaseDo {
Date startTime;
Date endTime;
}
所以在这里,我不知道如何在appointment.java中注释时隙。我已经搜索过了,我知道我需要使用
@Embedded
和@Embedded
标记,但不知道如何使用,有人能建议我这样做。你试过类似的方法吗
public class Appointment extends BaseDo implements Delivery {
private TimeSlot timeSlot;
@Embedded
public TimeSlot getTimeSlot() {
return timeSlot;
}
public void setTimeSlot (TimeSlot timeSlot) {
this.timeSlot= timeSlot;
}
}
@Embeddable
public class TimeSlot extends BaseDo {
Date startTime;
Date endTime;
@Column
public Date getStartTime(){
return startTime
}
public void setStartTime(Date startTime){
this.startTime = startTime;
}
@Column
public Date getEndTime(){
return endTime
}
public void setEndTime(Date endTime){
this.endTime = endTime;
}
}
这在hibernate文档中非常简单。即使我在这里有单独的时隙模式类表,我也不能使用您提供的参考,当约会表中也存在时隙属性时,您的参考是有用的,但在我的情况下不是@Taylor
public class Appointment extends BaseDo implements Delivery {
private TimeSlot timeSlot;
@Embedded
public TimeSlot getTimeSlot() {
return timeSlot;
}
public void setTimeSlot (TimeSlot timeSlot) {
this.timeSlot= timeSlot;
}
}
@Embeddable
public class TimeSlot extends BaseDo {
Date startTime;
Date endTime;
@Column
public Date getStartTime(){
return startTime
}
public void setStartTime(Date startTime){
this.startTime = startTime;
}
@Column
public Date getEndTime(){
return endTime
}
public void setEndTime(Date endTime){
this.endTime = endTime;
}
}