使用@PersistenceContext声明:
@PersistenceContext private EntityManager entityManager;
1、查询数据获取ResultSet结果集:
SessionImplementor session = entityManager.unwrap(SessionImplementor.class); Connection connection = session.connection(); PreparedStatement ps = connection.prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { Object value = rs.getObject(name); }