You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -425,11 +425,11 @@ public int getDefaultBatchSize() {
425
425
protectedEvalidateInsert(@NonnullEentity) {
426
426
if (isAutoGeneratedPrimaryKey()) {
427
427
if (!model.isDefaultPrimaryKey(entity.id())) {
428
-
thrownewPersistenceException("Primary key must not be set for auto-generated primary keys for inserts.");
428
+
thrownewPersistenceException("Primary key must not be set when inserting %s with an auto-generated primary key. Either omit the primary key value, or use insert(entity, true) to explicitly provide it.".formatted(model.type().getSimpleName()));
429
429
}
430
430
} else {
431
431
if (model.isDefaultPrimaryKey(entity.id())) {
432
-
thrownewPersistenceException("Primary key must be set for non-auto-generated primary keys for inserts.");
432
+
thrownewPersistenceException("Primary key must be set when inserting %s because the primary key is not auto-generated. Provide a non-default primary key value.".formatted(model.type().getSimpleName()));
433
433
}
434
434
}
435
435
returnentity;
@@ -440,21 +440,21 @@ protected E validateInsert(@Nonnull E entity, boolean ignoreAutoGenerate) {
440
440
returnvalidateInsert(entity);
441
441
}
442
442
if (model.isDefaultPrimaryKey(entity.id())) {
443
-
thrownewPersistenceException("Primary key must be set.");
443
+
thrownewPersistenceException("Primary key must be set when inserting %s with ignoreAutoGenerate enabled.".formatted(model.type().getSimpleName()));
444
444
}
445
445
returnentity;
446
446
}
447
447
448
448
protectedEvalidateUpdate(@NonnullEentity) {
449
449
if (model.isDefaultPrimaryKey(entity.id())) {
450
-
thrownewPersistenceException("Primary key must be set for updates.");
450
+
thrownewPersistenceException("Primary key must be set when updating %s. Provide a non-default primary key value to identify the row to update.".formatted(model.type().getSimpleName()));
451
451
}
452
452
returnentity;
453
453
}
454
454
455
455
protectedEvalidateDelete(@NonnullEentity) {
456
456
if (model.isDefaultPrimaryKey(entity.id())) {
457
-
thrownewPersistenceException("Primary key must be set for deletes.");
457
+
thrownewPersistenceException("Primary key must be set when deleting %s. Provide a non-default primary key value to identify the row to delete.".formatted(model.type().getSimpleName()));
458
458
}
459
459
returnentity;
460
460
}
@@ -471,7 +471,7 @@ protected E validateDelete(@Nonnull E entity) {
471
471
*/
472
472
protectedEvalidateUpsert(@NonnullEentity) {
473
473
if (!isAutoGeneratedPrimaryKey() && model.isDefaultPrimaryKey(entity.id())) {
474
-
thrownewPersistenceException("Primary key must be set for non-auto-generated primary keys for upserts.");
474
+
thrownewPersistenceException("Primary key must be set when upserting %s because the primary key is not auto-generated. Provide a non-default primary key value.".formatted(model.type().getSimpleName()));
475
475
}
476
476
returnentity;
477
477
}
@@ -558,7 +558,7 @@ public void insert(@Nonnull E entity) {
558
558
VALUES \0""", model.type(), entity))
559
559
.managed();
560
560
if (query.executeUpdate() != 1) {
561
-
thrownewPersistenceException("Insert failed.");
561
+
thrownewPersistenceException("Insert of %s failed. 0 rows were affected, which may indicate a trigger, constraint, or BEFORE INSERT hook prevented the row from being written.".formatted(model.type().getSimpleName()));
562
562
}
563
563
fireAfterInsert(entity);
564
564
}
@@ -586,7 +586,7 @@ public void insert(@Nonnull E entity, boolean ignoreAutoGenerate) {
thrownewPersistenceException("Insert of %s failed. 0 rows were affected, which may indicate a trigger, constraint, or BEFORE INSERT hook prevented the row from being written.".formatted(model.type().getSimpleName()));
590
590
}
591
591
fireAfterInsert(entity);
592
592
}
@@ -616,7 +616,7 @@ public ID insertAndFetchId(@Nonnull E entity) {
thrownewPersistenceException("Insert of %s failed. 0 rows were affected, which may indicate a trigger, constraint, or BEFORE INSERT hook prevented the row from being written.".formatted(model.type().getSimpleName()));
620
620
}
621
621
IDid = singleResult(isAutoGeneratedPrimaryKey()
622
622
? query.getGeneratedKeys(model.primaryKeyType())
@@ -871,9 +871,9 @@ public void update(@Nonnull E entity) {
871
871
.managed();
872
872
intresult = query.executeUpdate();
873
873
if (query.isVersionAware() && result == 0) {
874
-
thrownewOptimisticLockException("Update failed due to optimistic lock.");
874
+
thrownewOptimisticLockException("Update of %s failed due to optimistic lock. The entity may have been modified or deleted by another transaction.".formatted(model.type().getSimpleName()));
875
875
} elseif (result != 1) {
876
-
thrownewPersistenceException("Update failed.");
876
+
thrownewPersistenceException("Update of %s failed. 0 rows were affected, possibly because the row does not exist or a constraint prevented the update.".formatted(model.type().getSimpleName()));
thrownewPersistenceException("Upsert is not supported for joined sealed entities.");
908
+
thrownewPersistenceException("Upsert is not supported for joined sealed entity %s.".formatted(model.type().getSimpleName()));
909
909
}
910
910
}
911
911
@@ -1057,7 +1057,7 @@ public void delete(@Nonnull E entity) {
1057
1057
.managed()
1058
1058
.executeUpdate();
1059
1059
if (result != 1) {
1060
-
thrownewPersistenceException("Delete failed.");
1060
+
thrownewPersistenceException("Delete of %s failed. 0 rows were affected, possibly because the entity does not exist or a foreign key constraint prevents deletion.".formatted(model.type().getSimpleName()));
if (query.isVersionAware() && IntStream.of(result).anyMatch(r -> r == 0)) {
1719
-
thrownewOptimisticLockException("Update failed due to optimistic lock.");
1719
+
thrownewOptimisticLockException("Batch update of %s failed due to optimistic lock. One or more entities may have been modified or deleted by another transaction.".formatted(model.type().getSimpleName()));
1720
1720
} elseif (IntStream.of(result).anyMatch(r -> r != 1)) {
if (query.isVersionAware() && IntStream.of(result).anyMatch(r -> r == 0)) {
1738
-
thrownewOptimisticLockException("Update failed due to optimistic lock.");
1738
+
thrownewOptimisticLockException("Batch update of %s failed due to optimistic lock. One or more entities may have been modified or deleted by another transaction.".formatted(model.type().getSimpleName()));
1739
1739
} elseif (IntStream.of(result).anyMatch(r -> r != 1)) {
thrownewSqlTemplateException("Failed to convert value to database format for field '%s.%s'.".formatted(field.type().getSimpleName(), field.name()), e);
111
111
}
112
112
}
113
113
@@ -135,7 +135,7 @@ public Object fromDatabase(@Nonnull Object[] values,
135
135
DdbValue = databaseType.cast(raw);
136
136
returnconverter.fromDatabase(dbValue);
137
137
} catch (Throwablee) {
138
-
thrownewSqlTemplateException(e);
138
+
thrownewSqlTemplateException("Failed to convert database value to entity format for field '%s.%s'.".formatted(field.type().getSimpleName(), field.name()), e);
thrownewPersistenceException("Failed to instantiate converter " + converterClass.getName(), e);
95
+
thrownewPersistenceException("Failed to instantiate converter %s. Ensure the converter class has a public no-argument constructor.".formatted(converterClass.getName()), e);
"Cannot resolve generic types for converter " + converterClass.getName() +
209
-
" used on " + field.type().getName() + "." +
210
-
field.name()
208
+
"Cannot resolve generic types for converter %s used on %s.%s. Ensure the converter directly implements Converter<DatabaseType, EntityValueType> with concrete (non-generic) type arguments.".formatted(converterClass.getName(), field.type().getName(), field.name())
casenull -> thrownewSqlTemplateException("Null object not allowed, use IS_NULL operator instead.");
113
+
casenull -> thrownewSqlTemplateException("Null value not allowed as a direct parameter in a WHERE clause. To check for NULL, use the IS_NULL operator instead (e.g., where(field, IS_NULL)).");
default -> thrownewSqlTemplateException("Unsupported join target type: %s. Join targets must be either a table type (Class<? extends Data>) or a template expression.".formatted(join.target().getClass().getSimpleName()));
"Failed to join %s with %s. No matching foreign key found.".formatted(fromTable.getSimpleName(), toTable.getSimpleName()));
150
+
"Failed to join %s with %s: no matching foreign key relationship found. Ensure one of the types has an @FK-annotated field referencing the other, or use an explicit ON clause with a template-based join.".formatted(fromTable.getSimpleName(), toTable.getSimpleName()));
thrownewSqlTemplateException("Mismatch in PK/FK columns between tables.");
170
+
thrownewSqlTemplateException("Mismatch in PK/FK column count between %s and %s: found %d foreign key column(s) but %d primary key column(s). Ensure the foreign key definition matches the referenced primary key structure.".formatted(toTable.getSimpleName(), fromTable.getSimpleName(), fkColumns.size(), pkColumns.size()));
0 commit comments