Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- entityManager.getTransaction().begin();
- java.sql.Connection connection = entityManager.unwrap(java.sql.Connection.class); // unwraps the Connection class.
- ...
- entityManager.getTransaction().commit();
- entityManager.getTransaction().begin();
- UnitOfWork unitOfWork = (UnitOfWork)((JpaEntityManager)entityManager.getDelegate()).getActiveSession();
- unitOfWork.beginEarlyTransaction();
- Accessor accessor = unitOfWork.getAccessor();
- accessor.incrementCallCount(unitOfWork.getParent());
- accessor.decrementCallCount();
- java.sql.Connection connection = accessor.getConnection();
- ...
- entityManager.getTransaction().commit();
- Session hibernateSession = entityManager.unwrap(Session.class);
- Connection jdbcConnection = hibernateSession.connection();
- Connection connection = entityManager().unwrap(SessionImpl.class).connection();
- private void executeNative(final String query) {
- Session session = entityManager.unwrap(Session.class);
- session.doWork(new Work() {
- @Override
- public void execute(Connection connection) throws SQLException {
- Statement s = null;
- try {
- s = connection.createStatement();
- s.executeUpdate(query);
- }
- finally {
- if (s != null) {
- s.close();
- }
- }
- }
- });
- }
- SessionImpl sessionImpl = (SessionImpl) session;
- Connection conn = sessionImpl.connection();
- import java.sql.Connection;
- import org.apache.openjpa.persistence.OpenJPAEntityManager;
- import org.apache.openjpa.persistence.OpenJPAPersistence;
- public final class MsSqlDaoFactory {
- public static final Connection getConnection(final EntityManager entityManager) {
- OpenJPAEntityManager openJPAEntityManager = OpenJPAPersistence.cast(entityManager);
- Connection connection = (Connection) openJPAEntityManager.getConnection();
- return connection;
- }
- }
- Statement statement = null;
- EntityManager em = null;
- em = emf.createEntityManager();
- EntityTransaction et = em.getTransaction();
- if(!et.isActive()) {
- et.begin();
- }
- java.sql.Connection connection = em.unwrap(java.sql.Connection.class);
- String qquerry="SELE ...
- try {
- statement = connection.createStatement();
- ResultSet rs = statement.executeQuery(qquerry);
- if (!rs.next()) {
- return null;
- }
- else{
- wwwwas=rs.getString(4);
- }
- statement.close();
- }
- catch (SQLException e) {
- System.out.println("n b-03:"+e);
- throw new RuntimeException(e.getMessage(), e);
- }
- finally {
- try {
- // em.getTransaction().commit();
- if(connection != null )
- connection.close();
- }
- catch (Exception e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
Add Comment
Please, Sign In to add comment