-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Need help setting bidirectional 1-to-many association
PostPosted: Thu Jan 19, 2012 6:38 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.