{
log.log(Level.FINER, e.toString(), e);
String sqlState = e.getSQLState();
JdbcMetaData metaData = _persistenceUnit.getMetaData();
if (metaData.isUniqueConstraintSQLState(sqlState)) {
// jpa/0ga5
throw new EntityExistsException(L.l("Trying to persist an entity '{0}[{1}]' that already exists. Entity state '{2}'", entity.getClass().getName(), entity.__caucho_getPrimaryKey(), entity.__caucho_getEntityState()));
}
else if (metaData.isForeignKeyViolationSQLState(sqlState)) {
// jpa/0o42
throw new IllegalStateException(L.l("Trying to persist an entity of class '{0}' with PK '{1}' would break a foreign key constraint. The entity state is '{2}'. Please make sure there are associated entities for all required relationships. If you are merging an entity make sure the association fields are annotated with cascade=MERGE or cascade=ALL.", entity.getClass().getName(), entity.__caucho_getPrimaryKey(), entity.__caucho_getEntityState()));
}
throw e;