use of org.hibernate.JDBCException in project hibernate-orm by hibernate.
the class CustomInsertSQLWithIdentityColumnTest method testBadInsertionFails.
@Test
public void testBadInsertionFails() {
Session session = openSession();
session.beginTransaction();
Organization org = new Organization("hola!");
try {
session.save(org);
session.delete(org);
fail("expecting bad custom insert statement to fail");
} catch (JDBCException e) {
// expected failure
}
session.getTransaction().rollback();
session.close();
}
use of org.hibernate.JDBCException in project hibernate-orm by hibernate.
the class StoredProcedureTest method testInParametersNullnessPassingInNamedQueriesViaHints.
@Test
@SuppressWarnings("unchecked")
public void testInParametersNullnessPassingInNamedQueriesViaHints() {
Session session = openSession();
session.beginTransaction();
// similar to #testInParametersNotSet and #testInParametersNotSetPass in terms of testing
// support for specifying whether to pass NULL argument values or not. This version tests
// named procedure support via hints.
// first a fixture - this execution should fail
{
ProcedureCall query = session.getNamedProcedureCall("findUserRangeNoNullPassing");
query.getParameterRegistration(2).bindValue(2);
try {
query.getOutputs();
fail("Expecting failure due to missing parameter bind");
} catch (JDBCException ignore) {
}
}
// here we enable NULL passing via hint through a named parameter
{
ProcedureCall query = session.getNamedProcedureCall("findUserRangeNamedNullPassing");
query.getParameterRegistration("secondArg").bindValue(2);
query.getOutputs();
}
// here we enable NULL passing via hint through a named parameter
{
ProcedureCall query = session.getNamedProcedureCall("findUserRangeOrdinalNullPassing");
query.getParameterRegistration(2).bindValue(2);
query.getOutputs();
}
session.getTransaction().commit();
session.close();
}
use of org.hibernate.JDBCException in project kylo by Teradata.
the class FeedRestController method saveDraftFeed.
@POST
@Path("/{feedId}/versions/draft/entity")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Creates or saves a feed as draft version.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the feed metadata.", response = NifiFeed.class), @ApiResponse(code = 500, message = "An internal error occurred.", response = RestResponseStatus.class) })
@Nonnull
public Response saveDraftFeed(@Nonnull final FeedMetadata feedMetadata) {
try {
FeedMetadata update = getMetadataService().saveDraftFeed(feedMetadata);
NifiFeed feed = new NifiFeed(update, null);
feed.setSuccess(true);
return Response.ok(feed).build();
} catch (DuplicateFeedNameException e) {
log.info("Failed to create a new feed due to another feed having the same category/feed name: " + feedMetadata.getCategoryAndFeedDisplayName());
// Create an error message
String msg = "A feed already exists in the category \"" + e.getCategoryName() + "\" with name name \"" + e.getFeedName() + "\"";
// Add error message to feed
NifiFeed feed = new NifiFeed(feedMetadata, null);
feed.addErrorMessage(msg);
feed.setSuccess(false);
return Response.status(Status.CONFLICT).entity(feed).build();
} catch (NifiConnectionException e) {
throw e;
} catch (Exception e) {
log.error("Failed to create a new feed.", e);
// Create an error message
String msg = (e.getMessage() != null) ? "Error creating Feed: " + e.getMessage() : "An unknown error occurred while saving the feed.";
if (e.getCause() instanceof JDBCException) {
msg += ". " + ((JDBCException) e).getSQLException();
}
// Add error message to feed
NifiFeed feed = new NifiFeed(feedMetadata, null);
feed.addErrorMessage(msg);
feed.setSuccess(false);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(feed).build();
}
}
use of org.hibernate.JDBCException in project kylo by Teradata.
the class FeedRestController method createDraftFeed.
@POST
@Path("/draft/entity")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Creates a new feed as draft version.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the feed metadata.", response = NifiFeed.class), @ApiResponse(code = 500, message = "An internal error occurred.", response = RestResponseStatus.class) })
@Nonnull
public Response createDraftFeed(@Nonnull final FeedMetadata feedMetadata) {
try {
FeedMetadata update = getMetadataService().saveDraftFeed(feedMetadata);
NifiFeed feed = new NifiFeed(update, null);
feed.setSuccess(true);
return Response.ok(feed).build();
} catch (DuplicateFeedNameException e) {
log.info("Failed to create a new feed due to another feed having the same category/feed name: " + feedMetadata.getCategoryAndFeedDisplayName());
// Create an error message
String msg = "A feed already exists in the category \"" + e.getCategoryName() + "\" with name name \"" + e.getFeedName() + "\"";
// Add error message to feed
NifiFeed feed = new NifiFeed(feedMetadata, null);
feed.addErrorMessage(msg);
feed.setSuccess(false);
return Response.status(Status.CONFLICT).entity(feed).build();
} catch (NifiConnectionException e) {
throw e;
} catch (Exception e) {
log.error("Failed to create a new feed.", e);
// Create an error message
String msg = (e.getMessage() != null) ? "Error creating Feed: " + e.getMessage() : "An unknown error occurred while saving the feed.";
if (e.getCause() instanceof JDBCException) {
msg += ". " + ((JDBCException) e).getSQLException();
}
// Add error message to feed
NifiFeed feed = new NifiFeed(feedMetadata, null);
feed.addErrorMessage(msg);
feed.setSuccess(false);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(feed).build();
}
}
use of org.hibernate.JDBCException in project jo-client-platform by jo-source.
the class HibernateExceptionDecoratorImpl method decorate.
private Throwable decorate(final Throwable exception, final Throwable rootException) {
if (exception instanceof ConstraintViolationException) {
final ConstraintViolationException constViolationException = (ConstraintViolationException) exception;
final String message = constViolationException.getMessage();
final String constraintName = constViolationException.getConstraintName();
final String userBaseMessage = Messages.getString("HibernateExceptionDecoratorImpl.database_constraint_violated");
final String userMessage;
if (!EmptyCheck.isEmpty(constraintName)) {
userMessage = userBaseMessage.replace("%1", "'" + constraintName + "'");
} else {
final SQLException sqlException = constViolationException.getSQLException();
if (sqlException != null) {
if (!EmptyCheck.isEmpty(sqlException.getLocalizedMessage())) {
userMessage = sqlException.getLocalizedMessage();
} else if (!EmptyCheck.isEmpty(sqlException.getMessage())) {
userMessage = sqlException.getMessage();
} else {
userMessage = userBaseMessage.replace("%1", "");
}
} else {
userMessage = userBaseMessage.replace("%1", "");
}
}
return new ExecutableCheckException(null, message, userMessage);
} else if (exception instanceof OptimisticLockException && exception.getCause() instanceof StaleObjectStateException) {
return getStaleBeanException((StaleObjectStateException) exception);
} else if (exception instanceof UnresolvableObjectException) {
return getDeletedBeanException((UnresolvableObjectException) exception);
} else if (exception instanceof JDBCException && !excludeJDBCExceptionDecoration((JDBCException) exception)) {
return decorateJDBCException((JDBCException) exception);
} else if (exception instanceof InvocationTargetException && ((InvocationTargetException) exception).getTargetException() != null) {
return decorate(((InvocationTargetException) exception).getTargetException(), rootException);
} else if (exception.getCause() != null) {
return decorate(exception.getCause(), rootException);
}
return rootException;
}
Aggregations