我想弄清楚我在做什麼錯了,但我正在學習hibernate註釋並創建一個簡單的庫系統。基本上,一本書得到由一個人簽出,並最終在檢查這裏是我如何配置它。映射對象與映射實體
@Entity
@Table
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, unique = true)
private long barcode;
@Column(nullable = false)
private String name;
@OneToMany
@JoinTable(name = "checkoutsession", joinColumns = { @JoinColumn(name = "book") }, inverseJoinColumns = { @JoinColumn(name = "id")})
private List<CheckOutSession> checkOutSessions;
}
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false, unique = true)
private long barcode;
@Column(name = "firstname")
private String firstName;
@Column(name = "lastname")
private String lastName;
@OneToMany
@JoinTable(name = "checkoutsession", joinColumns = { @JoinColumn(name = "user") }, inverseJoinColumns = { @JoinColumn(name = "id")})
private List<CheckOutSession> checkOutSessions;
}
@Entity
@Table(name = "checkoutsession", uniqueConstraints = {@UniqueConstraint(columnNames={"book", "checkIn"})})
public class CheckOutSession {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne
@JoinColumn(name="book", nullable=false)
private Book book;
@ManyToOne
@JoinColumn(name="user", nullable=false)
private User user;
@Column(nullable = false)
private java.sql.Timestamp checkOut;
@Column
private java.sql.Timestamp checkIn;
}
我想不出什麼我有配置不正確我的生活。
[編輯]
當我嘗試拉一本書,它選擇了從checkoutsession加入checkoutsession加入用戶去世時說在‘字段列表’「未知列checkoutsess1_.check_in;
[EDIT2]
多一點背景,我有一個擴展JpaRepository一個BookDAO,當我打電話的findAll()是什麼創建查詢。
[EDIT3]
個休息類別:
@RestController
@RequestMapping("rest/books")
public class BookController {
@RequestMapping(method = RequestMethod.GET)
public List findBooks() {
return bookService.getAllBooks();
}
}
服務:
@Component
public class BookService {
private BookDao bookDao;
public List getAllBooks() {
return bookDao.findAll();
}
@Autowired
public void setBookDao(BookDao bookDao) {
this.bookDao = bookDao;
}
}
DAO:
public interface BookDao extends JpaRepository<Book, Long> {
}
感謝您的幫助!
有什麼問題? – Reimeus
你有什麼異常? – user2481857
對不起,只是編輯添加我得到的問題。 –