我努力做到以下几点:
public class Distance {
private Course courseA, courseB;
private int minDistance;
double cost;
private Long id;
public Distance() {
super();
}
public Distance(Course courseA, Course courseB, int minDistance, double cost) {
super();
this.courseA = courseA;
this.courseB = courseB;
this.minDistance = minDistance;
this.cost = cost;
}
@Override
public String toString() {
return "Distance [courseA=" + courseA + ", courseB=" + courseB
+ ", MinDistance=" + minDistance + ", Cost=" + cost + "]";
}
public Course getCourseA() {
return courseA;
}
public void setCourseA(Course courseA) {
this.courseA = courseA;
}
public Course getCourseB() {
return courseB;
}
public void setCourseB(Course courseB) {
this.courseB = courseB;
}
public int getMinDistance() {
return minDistance;
}
public void setMinDistance(int minDistance) {
this.minDistance = minDistance;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
this.cost = cost;
}
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
iii
如果课程是另一类课程,则设立一类课程:
public class Course {
private Long id;
private String name;
private Calendar date;
public Course() {
super();
}
public Course(Long id,String name, Calendar date) {
super();
this.id = id;
this.name = name;
this.date = date;
}
@Override
public String toString() {
return "Course [id=" + id + ", name=" + name + ", examDate=" + date
+ "]";
}
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Calendar getDate() {
return date;
}
public void setDate(Calendar date) {
this.date = date;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Course)) {
return false;
}
Course other = (Course) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
return true;
}
iii
I tried defining courseA and B as properties of Distance in "distance.hbm.xml" but that just yelled at me with an exception: org.hibernate.MappingException: Could not determine type for: database.datatypes.Course at table:distances...
I have tried declaring courseA and B as components, which "succeeded" but when I called session.load(Distance.class,1L)
it returned the right object, but the two courses were null pointers.
我如何界定它?
此外,我如何能够这样做,但对于图书馆的复杂班级(例如,java.util)。
感谢!
UPDATE: I found the way i could have my cake and work my way around it on the Distance-Course thing, but there is something important for me to work with: Course must have a date object in it. I would rather use java.util.Calendar, but if that is problematic, any other way to have a date that i could use instead?
再次感谢!