use of org.hibernate.engine.jdbc.spi.ResultSetReturn in project hibernate-orm by hibernate.
the class SQLExceptionConversionTest method testNotNullConstraint.
@Test
@TestForIssue(jiraKey = "HHH-7357")
public void testNotNullConstraint() {
final Session session = openSession();
session.beginTransaction();
final User user = new User();
user.setUsername("Lukasz");
session.save(user);
session.flush();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
final JdbcCoordinator jdbcCoordinator = ((SessionImplementor) session).getJdbcCoordinator();
final StatementPreparer statementPreparer = jdbcCoordinator.getStatementPreparer();
final ResultSetReturn resultSetReturn = jdbcCoordinator.getResultSetReturn();
PreparedStatement ps = null;
try {
ps = statementPreparer.prepareStatement("UPDATE T_USER SET user_name = ? WHERE user_id = ?");
// Attempt to update user name to NULL (NOT NULL constraint defined).
ps.setNull(1, Types.VARCHAR);
ps.setLong(2, user.getId());
resultSetReturn.executeUpdate(ps);
fail("UPDATE should have failed because of not NULL constraint.");
} catch (ConstraintViolationException ignore) {
// expected outcome
} finally {
releaseStatement(session, ps);
}
}
});
session.getTransaction().rollback();
session.close();
}
use of org.hibernate.engine.jdbc.spi.ResultSetReturn in project hibernate-orm by hibernate.
the class CursorFromCallableTest method executeStatement.
private void executeStatement(final String sql) {
final Session session = openSession();
session.getTransaction().begin();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
final JdbcCoordinator jdbcCoordinator = ((SessionImplementor) session).getJdbcCoordinator();
final StatementPreparer statementPreparer = jdbcCoordinator.getStatementPreparer();
final ResultSetReturn resultSetReturn = jdbcCoordinator.getResultSetReturn();
PreparedStatement preparedStatement = null;
try {
preparedStatement = statementPreparer.prepareStatement(sql);
resultSetReturn.execute(preparedStatement);
} finally {
if (preparedStatement != null) {
try {
jdbcCoordinator.getResourceRegistry().release(preparedStatement);
} catch (Throwable ignore) {
// ignore...
}
}
}
}
});
session.getTransaction().commit();
session.close();
}
Aggregations