这是我的课:
public class TrainLate {
private int id;
private Date startDate;
private Date endDate;
private Set<TrainSchedule> ts=new HashSet<TrainSchedule>();
public TrainLate(){}
public TrainLate(int id, Date startDate, Date endDate) {
super();
this.id = id;
this.startDate = startDate;
this.endDate = endDate;
}
// setters and getters...
}
日期类型是java.sql.Date
在另一堂课中,我使用 HQL:
String hql="SELECT new TrainLate(id,startDate,endDate) FROM TrainLate "+ "WHERE id="+String.valueOf(index);
其中 index 是一个 int 参数。
这是“TrainLate.hbm.xml”:
<class name="classes.TrainLate">
<id name="id">
<generator class="native"/>
</id>
<property name="startDate"/>
<property name="endDate"/>
<set name="ts" lazy="false" cascade="all-delete-orphan" inverse="true">
<key column="trainLateID" />
<one-to-many class="classes.TrainSchedule" />
</set>
</class>
这是一个例外:
Unable to locate appropriate constructor on class [classes.TrainLate] [SELECT new TrainLate(id,startDate,endDate) FROM classes.TrainLate WHERE id=0]
其中“类”是包名。