Bug 266 : Various Bug fixes for Embedded Id's ... (patches from Rien)
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.6.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
06/04/2010
Updated 
06/04/2010
Type 
Bug
 
Attachments 
No attachments

Index: src/main/java/com/avaje/ebeaninternal/server/persist/dml/InsertHandler.java
===================================================================
--- src/main/java/com/avaje/ebeaninternal/server/persist/dml/InsertHandler.java (revision 915)
+++ src/main/java/com/avaje/ebeaninternal/server/persist/dml/InsertHandler.java (working copy)
@@ -32,6 +32,7 @@
import com.avaje.ebeaninternal.server.core.Message;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
+import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.DmlUtil;
import com.avaje.ebeaninternal.server.type.DataBind;

@@ -226,4 +227,9 @@
}
}
}
+
+ @Override
+ public boolean isIncluded(BeanProperty prop) {
+ return prop.isDbInsertable() && (super.isIncluded(prop));
+ }
}
Index: src/main/java/com/avaje/ebeaninternal/server/persist/dml/UpdateHandler.java
===================================================================
--- src/main/java/com/avaje/ebeaninternal/server/persist/dml/UpdateHandler.java (revision 915)
+++ src/main/java/com/avaje/ebeaninternal/server/persist/dml/UpdateHandler.java (working copy)
@@ -94,7 +94,7 @@
@Override
public boolean isIncluded(BeanProperty prop) {

- return updatedProperties == null || updatedProperties.contains(prop.getName());
+ return prop.isDbUpdatable() && (updatedProperties == null || updatedProperties.contains(prop.getName()));
}

}
Index: src/main/java/com/avaje/ebeaninternal/server/deploy/id/IdBinderEmbedded.java
===================================================================
--- src/main/java/com/avaje/ebeaninternal/server/deploy/id/IdBinderEmbedded.java (revision 915)
+++ src/main/java/com/avaje/ebeaninternal/server/deploy/id/IdBinderEmbedded.java (working copy)
@@ -122,10 +122,13 @@
}

public Object[] getIdValues(Object bean) {
+ bean = embIdProperty.getValue(bean);
+
Object[] bindvalues = new Object[props.length];
for (int i = 0; i < props.length; i++) {
bindvalues[i] = props[i].getValue(bean);
}
+
return bindvalues;
}

@@ -162,12 +165,12 @@
public Object read(DbReadContext ctx) throws SQLException {

Object embId = idDesc.createVanillaBean();
- boolean notNull = false;
+ boolean notNull = true;

for (int i = 0; i < props.length; i++) {
Object value = props[i].readSet(ctx, embId, null);
- if (value != null) {
- notNull = true;
+ if (value == null) {
+ notNull = false;
}
}

@@ -228,6 +231,10 @@
sb.append(prefix);
sb.append(".");
}
+
+ sb.append(embIdProperty.getName());
+ sb.append(".");
+
sb.append(props[i].getName());
sb.append(" ").append(operator);
sb.append(" ? ");
Index: src/main/java/com/avaje/ebeaninternal/server/deploy/id/ImportedIdEmbedded.java
===================================================================
--- src/main/java/com/avaje/ebeaninternal/server/deploy/id/ImportedIdEmbedded.java (revision 915)
+++ src/main/java/com/avaje/ebeaninternal/server/deploy/id/ImportedIdEmbedded.java (working copy)
@@ -64,7 +64,7 @@
public void dmlAppend(GenerateDmlRequest request) {

for (int i = 0; i < imported.length; i++) {
- request.appendColumn(imported[i].localDbColumn);
+ request.appendColumn(imported[i].localDbColumn);
}
}

@@ -77,17 +77,21 @@

if (embeddedId == null){
for (int i = 0; i < imported.length; i++) {
- request.appendColumnIsNull(imported[i].localDbColumn);
+ if (imported[i].owner.isDbUpdatable()) {
+ request.appendColumnIsNull(imported[i].localDbColumn);
+ }
}
} else {

for (int i = 0; i < imported.length; i++) {
+ if (imported[i].owner.isDbUpdatable()) {
Object value = imported[i].foreignProperty.getValue(embeddedId);
if (value == null){
request.appendColumnIsNull(imported[i].localDbColumn);
} else {
request.appendColumn(imported[i].localDbColumn);
}
+ }
}
}
}
@@ -101,10 +105,14 @@

public void bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {

- Object embeddedId = foreignAssocOne.getValue(bean);
+ Object embeddedId = null;
+
+ if (bean != null) {
+ embeddedId = foreignAssocOne.getValue(bean);
+ }

if (embeddedId == null){
- for (int i = 0; i < imported.length; i++) {
+ for (int i = 0; i < imported.length; i++) {
request.bind(null, imported[i].foreignProperty, imported[i].localDbColumn, true);
}

 
Rob 06 Apr 09:38
Fixed in HEAD

Thanks Rien.

I reviewed these changes and they are all good. Fixed in HEAD.

woResponse

Upload a file