mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2148 - PersistenceException: No ScalarType registered for class java.util.LinkedHashMap
This commit is contained in:
@@ -3,6 +3,9 @@ package io.ebeaninternal.server.querydefn;
|
||||
import io.ebean.ExpressionList;
|
||||
import io.ebean.ProfileLocation;
|
||||
import io.ebean.UpdateQuery;
|
||||
import io.ebean.core.type.ScalarType;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
* Default implementation of UpdateQuery.
|
||||
@@ -10,23 +13,30 @@ import io.ebean.UpdateQuery;
|
||||
public class DefaultUpdateQuery<T> implements UpdateQuery<T> {
|
||||
|
||||
private final OrmUpdateProperties values = new OrmUpdateProperties();
|
||||
|
||||
private final DefaultOrmQuery<T> query;
|
||||
private final BeanDescriptor<T> descriptor;
|
||||
|
||||
public DefaultUpdateQuery(DefaultOrmQuery<T> query) {
|
||||
this.query = query;
|
||||
this.descriptor = query.getBeanDescriptor();
|
||||
query.setUpdateProperties(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateQuery<T> set(String property, Object value) {
|
||||
values.set(property, value);
|
||||
if (value == null) {
|
||||
values.setNull(property);
|
||||
} else {
|
||||
final BeanProperty beanProperty = descriptor.getBeanProperty(property);
|
||||
final ScalarType<Object> scalarType = (beanProperty == null) ? null: beanProperty.getScalarType();
|
||||
values.set(property, value, scalarType);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateQuery<T> setNull(String property) {
|
||||
values.set(property, null);
|
||||
values.setNull(property);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+14
-11
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.querydefn;
|
||||
|
||||
import io.ebean.core.type.ScalarType;
|
||||
import io.ebeaninternal.server.deploy.DeployParser;
|
||||
import io.ebeaninternal.server.persist.Binder;
|
||||
import io.ebeaninternal.server.type.DataBind;
|
||||
@@ -53,9 +54,11 @@ public class OrmUpdateProperties {
|
||||
private static class SimpleValue extends Value {
|
||||
|
||||
final Object value;
|
||||
final ScalarType<Object> scalarType;
|
||||
|
||||
SimpleValue(Object value) {
|
||||
SimpleValue(Object value, ScalarType<Object> scalarType) {
|
||||
this.value = value;
|
||||
this.scalarType = scalarType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +73,11 @@ public class OrmUpdateProperties {
|
||||
|
||||
@Override
|
||||
public void bind(Binder binder, DataBind dataBind) throws SQLException {
|
||||
binder.bindObject(dataBind, value);
|
||||
if (scalarType != null) {
|
||||
scalarType.bind(dataBind, value);
|
||||
} else {
|
||||
binder.bindObject(dataBind, value);
|
||||
}
|
||||
dataBind.append(value).append(",");
|
||||
}
|
||||
}
|
||||
@@ -115,16 +122,12 @@ public class OrmUpdateProperties {
|
||||
*/
|
||||
private final LinkedHashMap<String, Value> values = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Normal set property.
|
||||
*/
|
||||
public void set(String propertyName, Object value) {
|
||||
if (value == null) {
|
||||
values.put(propertyName, NULL_VALUE);
|
||||
public void set(String propertyName, Object value, ScalarType<Object> scalarType) {
|
||||
values.put(propertyName, new SimpleValue(value, scalarType));
|
||||
}
|
||||
|
||||
} else {
|
||||
values.put(propertyName, new SimpleValue(value));
|
||||
}
|
||||
public void setNull(String propertyName) {
|
||||
values.put(propertyName, NULL_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user