I've tried many solutions for websites and forums, but still got little luck setting up the one-to-many association, please help
I have tables like:
Code:
create table booking (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
user varchar(30) not null,
reason varchar(200) not null,
requestTime datetime not null,
status varchar(1) not null,
PRIMARY KEY (id)
);
create table bookingslot (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
startdate datetime not null,
status varchar(1) not null,
bookingId smallint not null,
facilityId smallint not null,
PRIMARY KEY (id)
);
With Booking class:
Code:
@Entity
@Table(name="booking")
public class Booking {
@GeneratedValue (strategy=GenerationType.AUTO)
@Id
int id;
String user;
String reason;
String status;
Date requestTime;
@OneToMany(cascade = {CascadeType.REMOVE}, mappedBy="booking", fetch = FetchType.LAZY)
Set<BookingSlot> bookingslot = new HashSet<BookingSlot>();
@Column(name="id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="user")
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
@Column(name="reason")
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
@Column(name="status")
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Set<BookingSlot> getBookingSlot() {
return bookingslot;
}
public void setBookingSlot(Set<BookingSlot> slots) {
this.bookingslot = slots;
}
@Column(name="requestTime")
public Date getRequestTime() {
return requestTime;
}
public void setRequestTime(Date requestTime) {
this.requestTime = requestTime;
}
}
And BookingSlot class:
Code:
@Entity
@Table(name="bookingslot")
public class BookingSlot {
int id;
Date startDate;
String status;
@JoinColumn(name = "bookingId")
@ManyToOne(optional = true)
@ForeignKey(name = "bookingId")
Booking booking;
@Id
@Column(name="id")
@GeneratedValue (strategy=GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="startdate")
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
@Column(name="status")
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Booking getBooking() {
return booking;
}
public void setBooking(Booking booking) {
this.booking = booking;
}
/*@ManyToOne
@JoinColumn(name = "facilityId")
Facility facility;
public Facility getFacility() {
return facility;
}
public void setFacility(Facility facility) {
this.facility = facility;
}*/
}
I keep getting MappingException:
Code:
Initial SessionFactory creation failed.
org.hibernate.MappingException: Could not determine type for: com.hsbc.ilab.booking.vo.Booking, at table: bookingslot, for columns: [org.hibernate.mapping.Column(booking)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:304)
...
any clue?