0
對於一個項目,我想獲得一個LEFT JOIN與標準的工作,但我不「噸得到我想要的東西Hibernate的標準LEFT JOIN
我想這樣做:從UserBooks選擇左側的書籍JOIN書籍,.. .. 但我沒有得到任何
這是我的時刻了:
@SuppressWarnings("unchecked")
public List<Books> getBooksByTitle(int userID, String Title) {
List<Books> books = null;
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
Criteria c = session.createCriteria(UserBooks.class, "userBooks");
c.setFetchMode("userBooks.book", FetchMode.JOIN);
c.createAlias("userBooks.book", "books");
c.setProjection(Projections.property("books")) ;
c.add(Restrictions.eq("userBooks.id", userID));
c.add(Restrictions.like("books.title", "%"+ Title + "%"));
books = c.list();
for (Books allBooks : (List<Books>)books) {
System.out.println(">>>>>" + allBooks.getTitle());
}
tx.rollback();
session.close();
factory.close();
return books;
}
你想加入什麼桌子? –