@
Autowired private OauthClientService oauthClientService;
@
Autowired private EntityManager entityManager;
@
Test public void testSession() {
Query query = entityManager.createNativeQuery("SELECT id from oauth_client");
DetachedCriteria criteria = DetachedCriteria.forClass(Object.class)
// 这里需要类型绑定,通过数据库类型和 JAVA 类型进行转换
.add(Property.forName("id")
.eq(5L));
String s = criteria.toString();
EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
Session session = sessionFactory.openSession();
Criteria executableCriteria = criteria.getExecutableCriteria(session);
List list = executableCriteria.list();
}
@
WEBUG JPA 层面代码.