本文整理汇总了Java中org.springframework.orm.jpa.JpaSystemException类的典型用法代码示例。如果您正苦于以下问题:Java JpaSystemException类的具体用法?Java JpaSystemException怎么用?Java JpaSystemException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JpaSystemException类属于org.springframework.orm.jpa包,在下文中一共展示了JpaSystemException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: persistAndRetryIfMacCollision
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
private VmNicVO persistAndRetryIfMacCollision(VmNicVO vo) {
int tries = 5;
while (tries-- > 0) {
try {
vo = dbf.persistAndRefresh(vo);
return vo;
} catch (JpaSystemException e) {
if (e.getRootCause() instanceof MySQLIntegrityConstraintViolationException &&
e.getRootCause().getMessage().contains("Duplicate entry")) {
logger.debug(String.format("Concurrent mac allocation. Mac[%s] has been allocated, try allocating another one. " +
"The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " +
"we will try finding another mac", vo.getMac()));
logger.trace("", e);
vo.setMac(NetworkUtils.generateMacWithDeviceId((short) vo.getDeviceId()));
} else {
throw e;
}
}
}
return null;
}
示例2: handleJpaException
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
/**
* 处理JPA的异常
*
* @param ex
* @param request
* @return
*/
@ExceptionHandler(value = {JpaSystemException.class})
public ResponseEntity<ErrorResponse> handleJpaException(Exception ex, WebRequest request) {
if (log.isDebugEnabled()) {
log.debug("handling exception ==> " + request.getDescription(true));
}
RestException rex = new RestException(PARAMS_RESOLUTION_ERROR, ex.getLocalizedMessage());
ErrorResponse res = new ErrorResponse(rex);
return new ResponseEntity<>(res, rex.getHttpStatus());
}
示例3: testDuplicateUniqueValuesAreRejectedWithChecking_TestingDisabled
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test
public void testDuplicateUniqueValuesAreRejectedWithChecking_TestingDisabled() {
myDaoConfig.setUniqueIndexesCheckedBeforeSave(false);
createUniqueBirthdateAndGenderSps();
Patient pt1 = new Patient();
pt1.setGender(Enumerations.AdministrativeGender.MALE);
pt1.setBirthDateElement(new DateType("2011-01-01"));
myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
try {
myPatientDao.create(pt1).getId().toUnqualifiedVersionless();
fail();
} catch (JpaSystemException e) {
// good
}
}
示例4: delete
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@RequestMapping(value = "/{configType}_configs/{configName}", method = RequestMethod.DELETE, produces = "text/html")
public String delete(@PathVariable String configType, @PathVariable("configName") String configName, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) throws Exception {
Configuration configuration = Configuration.findConfigurationsByNameEquals(configName).getSingleResult();
try {
for (Transformer t:configuration.getTransformers()) t.removeOrphanedWiredTransformers(); // this is expensive and should go soon
configuration.remove();
} catch (JpaSystemException e) {
// assuming a possibly still exotically ocurring legacy error: a wire
// of a *different* config uses this matcher, hence it would have a
// foreign key into the void and complains so the matcher can't be
// deleted and this config neither..
configuration.fixMatchersForAlienWire();
configuration.getWiring().clear();
configuration.merge();
configuration.removeTransformers();
configuration = Configuration.findConfigurationsByNameEquals(configName).getSingleResult();
configuration.remove();
}
uiModel.asMap().clear();
uiModel.addAttribute("page", (page == null) ? "1" : page.toString());
uiModel.addAttribute("size", (size == null) ? "10" : size.toString());
return String.format("redirect:/%s_configs", configType);
}
示例5: delete
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@UICommand
@Override
public String delete()
{
String copyName = getEntity().getName();
try {
Library library = getEntity().getLibrary();
getDao().deleteEntity(getEntity());
showMessage("deletedEntity", "copy " + copyName);
_libraryViewer.getContextualSearchResults().reload();
return _libraryViewer.viewEntity(library);
}
catch (JpaSystemException e) {
if (e.contains(ConstraintViolationException.class)) {
showMessage("cannotDeleteEntityInUse", "Copy " + copyName);
return REDISPLAY_PAGE_ACTION_RESULT;
}
else {
throw e;
}
}
}
示例6: test02_CreateYourEntity_DuplicateEntry
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test(expected = JpaSystemException.class)
public void test02_CreateYourEntity_DuplicateEntry() {
LOGGER.info("Running: test02_CreateYourEntity");
YourEntity yourEntity = new YourEntity();
yourEntity.setEntityEmailAddress(USER_EMAIL); // Will Fail since it is not Unique ...
yourEntity.setCredentials("password");
yourEntity.setEntityGivenName("Ro");
yourEntity.setEntitySurname("Bot");
yourEntity.setStatus(YourEntityStatus.ACTIVE);
yourEntity.setYourEntityRoles(new HashSet<>());
yourEntity.setEntityProperties(new HashMap<>());
yourEntity.setYourEntityOrganizations(new HashSet<>());
identityProviderEntityManager.saveYourEntity(yourEntity);
}
示例7: handleOtherExceptions
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
/**
* Geef HTTP code 500 bij JPA fouten.
* @param ex exception
* @return fout omschrijving
*/
@ExceptionHandler(JpaSystemException.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ExceptionResponse handleOtherExceptions(final JpaSystemException ex) {
LOG.warn("JPA exceptie opgetreden", ex);
return new ExceptionResponse(
"Databaseregels geschonden",
"Ingevoerde gegevens komen al voor in de database of schenden integriteitsregels van de database");
}
示例8: testSaveWithExistingEntityWithNullId
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test
public void testSaveWithExistingEntityWithNullId() throws Exception {
final RealizationEntity entity = getRealizationEntity();
final RealizationEntity saved = repository.saveAndFlush(entity);
saved.setId(null);
exception.expect(JpaSystemException.class);
repository.saveAndFlush(saved);
}
示例9: testSaveWithExistingEntityWithNullId
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test
public void testSaveWithExistingEntityWithNullId() throws Exception {
final UserEntity entity = TestUtil.getUserEntity();
final UserEntity saved = repository.saveAndFlush(entity);
saved.setId(null);
exception.expect(JpaSystemException.class);
repository.saveAndFlush(saved);
}
示例10: testSaveNullId
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test
public void testSaveNullId() throws Exception {
final CredentialsEntity entity = getCredentialsEntity();
entity.setId(null);
exception.expect(JpaSystemException.class);
exception.expectMessage(CredentialsEntity.class.getName());
repository.saveAndFlush(entity);
}
示例11: testSaveWithExistingEntityWithNullId
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test
public void testSaveWithExistingEntityWithNullId() throws Exception {
final ImageEntity entity = getImageEntity();
final ImageEntity saved = repository.saveAndFlush(entity);
saved.setId(null);
exception.expect(JpaSystemException.class);
repository.saveAndFlush(saved);
}
示例12: testSaveWithExistingEntityWithNullId
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test
public void testSaveWithExistingEntityWithNullId() throws Exception {
final ExperimentEntity entity = getExperimentEntity();
final ExperimentEntity saved = repository.saveAndFlush(entity);
saved.setId(null);
exception.expect(JpaSystemException.class);
repository.saveAndFlush(saved);
}
示例13: testSaveWithExistingEntityWithNullId
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test
public void testSaveWithExistingEntityWithNullId() throws Exception {
final DeterLabProjectEntity entity = Util.getDeterLabProjectEntity();
final DeterLabProjectEntity saved = repository.saveAndFlush(entity);
saved.setId(null);
exception.expect(JpaSystemException.class);
repository.saveAndFlush(saved);
}
示例14: testSaveWithExistingEntityWithNullId
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test
public void testSaveWithExistingEntityWithNullId() throws Exception {
final DeterLabUserEntity entity = Util.getDeterlabUserEntity();
final DeterLabUserEntity saved = repository.saveAndFlush(entity);
saved.setId(null);
exception.expect(JpaSystemException.class);
repository.saveAndFlush(saved);
}
示例15: testCreateStudentsWithNonUniqueIds
import org.springframework.orm.jpa.JpaSystemException; //导入依赖的package包/类
@Test(expected = JpaSystemException.class)
public void testCreateStudentsWithNonUniqueIds() {
Student student1 = new Student();
student1.setUniqueId("4113947bec18b7ad_1");
studentDao.create(student1);
Student student2 = new Student();
student2.setUniqueId("4113947bec18b7ad_1");
studentDao.create(student2);
}