I'm trying to figure out what I'm doing wrong with this, but I'm learning hibernate annotations and creating a simple library system. Basically, a book gets checked out by a person, and eventually checked in. Here's how I have it configured:
@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;
}
I can't figure out for the life of me what I've got configured incorrectly.
[EDIT]
when I try to pull a book it is selecting everything from checkoutsession join checkoutsession join user and dies saying "Unknown column checkoutsess1_.check_in in 'field list';
[EDIT2]
A little more context, I have a BookDAO that extends JpaRepository and when I call findAll() is what's creating that query.
[EDIT3]
Rest Class:
@RestController
@RequestMapping("rest/books")
public class BookController {
@RequestMapping(method = RequestMethod.GET)
public List findBooks() {
return bookService.getAllBooks();
}
}
Service:
@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> {
}
Thanks for any help!