Hibernate基于外键查询


public List<Order> getClientOrder(String clientId) {

		Session session = null;
		List<Order> orderList = null;
		try {
			session = HibernateUtil.getSession();
			session.beginTransaction();
			orderList = session.createQuery("from Order o where o.client.clientId = ?")
								.setParameter(1,clientId)
								.list();
			session.getTransaction().commit();
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		} finally {
			HibernateUtil.closeSession(session);
		}

		return orderList;
	}

你可能感兴趣的:(java,Hibernate)