Don't assign default values to columns that have a @GeneratedValue annotation
because those will have their values set at insertion time and the database might rightly freak out about the inconsistency of saying that the field has a constant default value.
This commit is contained in:
@@ -459,7 +459,7 @@ public abstract class FieldMarshaller<T>
|
||||
|
||||
protected Field _field;
|
||||
protected String _columnName;
|
||||
ColumnDefinition _columnDefinition;
|
||||
protected ColumnDefinition _columnDefinition;
|
||||
protected Computed _computed;
|
||||
protected GeneratedValue _generatedValue;
|
||||
}
|
||||
|
||||
@@ -154,15 +154,16 @@ public abstract class SQLBuilder
|
||||
"Primitive Java type cannot be nullable [field=" + field.getName() + "]");
|
||||
}
|
||||
|
||||
if (defaultValue == null) {
|
||||
// Java primitive types cannot be null, so we provide a default value for these columns
|
||||
// that matches Java's default for primitive types; however, if the column has a generated
|
||||
// value, don't provide a default because that will anger the database Gods
|
||||
if (defaultValue == null && genValue == null) {
|
||||
if (field.getType().equals(Byte.TYPE) ||
|
||||
field.getType().equals(Short.TYPE) ||
|
||||
field.getType().equals(Integer.TYPE) ||
|
||||
field.getType().equals(Long.TYPE) ||
|
||||
field.getType().equals(Float.TYPE) ||
|
||||
field.getType().equals(Double.TYPE)) {
|
||||
// Java primitive types cannot be null, so we provide a default value for these
|
||||
// columns that matches Java's default for primitive types
|
||||
field.getType().equals(Short.TYPE) ||
|
||||
field.getType().equals(Integer.TYPE) ||
|
||||
field.getType().equals(Long.TYPE) ||
|
||||
field.getType().equals(Float.TYPE) ||
|
||||
field.getType().equals(Double.TYPE)) {
|
||||
defaultValue = "0";
|
||||
|
||||
} else if (field.getType().equals(Boolean.TYPE)) {
|
||||
|
||||
Reference in New Issue
Block a user