mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1785 - Bean gets replaced on json deserialization with primitive 'null' id
This commit is contained in:
@@ -112,6 +112,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.ebeaninternal.server.persist.DmlUtil.isNullOrZero;
|
||||
|
||||
/**
|
||||
* Describes Beans including their deployment information.
|
||||
*/
|
||||
@@ -3210,7 +3212,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
}
|
||||
|
||||
boolean hasIdValue(EntityBean bean) {
|
||||
return (idProperty != null && !DmlUtil.isNullOrZero(idProperty.getValue(bean)));
|
||||
return (idProperty != null && !isNullOrZero(idProperty.getValue(bean)));
|
||||
}
|
||||
|
||||
boolean hasVersionProperty(EntityBeanIntercept ebi) {
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.ebeaninternal.server.persist.DmlUtil.isNullOrZero;
|
||||
|
||||
class BeanDescriptorJsonHelp<T> {
|
||||
|
||||
private final BeanDescriptor<T> desc;
|
||||
@@ -158,7 +160,7 @@ class BeanDescriptorJsonHelp<T> {
|
||||
}
|
||||
Object contextBean = null;
|
||||
Object id = desc.beanId(bean);
|
||||
if (id != null) {
|
||||
if (!isNullOrZero(id)) {
|
||||
// check if the bean has already been loaded
|
||||
contextBean = readJson.persistenceContextPutIfAbsent(id, bean, desc);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.ebeaninternal.server.persist.DmlUtil.isNullOrZero;
|
||||
|
||||
/**
|
||||
* Persister implementation using DML.
|
||||
* <p>
|
||||
@@ -1227,11 +1229,9 @@ public final class DefaultPersister implements Persister {
|
||||
EntityBean bean = request.getEntityBean();
|
||||
Object uid = idProp.getValue(bean);
|
||||
|
||||
if (DmlUtil.isNullOrZero(uid)) {
|
||||
|
||||
if (isNullOrZero(uid)) {
|
||||
// generate the nextId and set it to the property
|
||||
Object nextId = desc.nextId(request.getTransaction());
|
||||
|
||||
// cast the data type if required and set it
|
||||
desc.convertSetId(nextId, bean);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.ebeaninternal.server.persist.DmlUtil.isNullOrZero;
|
||||
|
||||
/**
|
||||
* Saves the details for a OneToMany or ManyToMany relationship (entity beans).
|
||||
*/
|
||||
@@ -222,7 +224,7 @@ public class SaveManyBeans extends SaveManyBase {
|
||||
}
|
||||
if (detailBean instanceof EntityBean) {
|
||||
Object id = targetDescriptor.getId((EntityBean) detailBean);
|
||||
if (!DmlUtil.isNullOrZero(id)) {
|
||||
if (!isNullOrZero(id)) {
|
||||
// remember the Id (other details not in the collection) will be removed
|
||||
detailIds.add(id);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import io.ebeaninternal.api.SpiTransaction;
|
||||
import io.ebeaninternal.server.core.Message;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.persist.DmlUtil;
|
||||
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.PersistenceException;
|
||||
@@ -15,6 +14,8 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static io.ebeaninternal.server.persist.DmlUtil.isNullOrZero;
|
||||
|
||||
/**
|
||||
* Insert bean handler.
|
||||
*/
|
||||
@@ -66,7 +67,7 @@ public class InsertHandler extends DmlHandler {
|
||||
|
||||
Object idValue = desc.getId(bean);
|
||||
|
||||
boolean withId = !DmlUtil.isNullOrZero(idValue);
|
||||
boolean withId = !isNullOrZero(idValue);
|
||||
|
||||
// check to see if we are going to use generated keys
|
||||
if (!withId) {
|
||||
|
||||
Reference in New Issue
Block a user