Test case and Fix for #67 - Bug - @AttributeOverrides annotation for attribute definition in entity does not work for embedded primary keys

This commit is contained in:
Rob Bygrave committed 2014-04-27 00:57:29 +12:00
1 parent dde59db411
commit d16d92db54
8 files changed
+155 -19

No files matched your search

@@ -1,11 +1,8 @@
package com.avaje.ebeaninternal.server.deploy.parse;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.EmbeddedId;
@@ -210,20 +207,7 @@ public class AnnotationAssocOnes extends AnnotationParser {
prop.getDeployEmbedded().putAll(propMap);
}
AttributeOverrides attrOverrides = get(prop, AttributeOverrides.class);
if (attrOverrides != null) {
HashMap<String, String> propMap = new HashMap<String, String>();
AttributeOverride[] aoArray = attrOverrides.value();
for (int i = 0; i < aoArray.length; i++) {
String propName = aoArray[i].name();
String columnName = aoArray[i].column().name();
propMap.put(propName, columnName);
}
prop.getDeployEmbedded().putAll(propMap);
}
readEmbeddedAttributeOverrides(prop);
}
}
@@ -22,6 +22,7 @@ import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.avaje.ebean.annotation.CreatedTimestamp;
import com.avaje.ebean.annotation.EmbeddedColumns;
import com.avaje.ebean.annotation.Encrypted;
@@ -37,6 +38,7 @@ import com.avaje.ebean.config.dbplatform.IdType;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedPropertyFactory;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssoc;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyCompound;
import com.avaje.ebeaninternal.server.idgen.UuidIdGenerator;
import com.avaje.ebeaninternal.server.lib.util.StringHelper;
@@ -102,6 +104,12 @@ public class AnnotationFields extends AnnotationParser {
prop.setEmbedded(true);
}
if (prop instanceof DeployBeanPropertyAssocOne<?>) {
if (prop.isId() && !prop.isEmbedded()) {
prop.setEmbedded(true);
}
readEmbeddedAttributeOverrides((DeployBeanPropertyAssocOne<?>)prop);
}
}
private void readField(DeployBeanProperty prop) {
@@ -1,9 +1,14 @@
package com.avaje.ebeaninternal.server.deploy.parse;
import java.util.HashMap;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import com.avaje.ebeaninternal.server.deploy.BeanCascadeInfo;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocOne;
/**
* Base class for reading deployment annotations.
@@ -48,4 +53,25 @@ public abstract class AnnotationParser extends AnnotationBase {
}
}
/**
* Read an AttributeOverrides if they exist for this embedded bean.
*/
protected void readEmbeddedAttributeOverrides(DeployBeanPropertyAssocOne<?> prop) {
AttributeOverrides attrOverrides = get(prop, AttributeOverrides.class);
if (attrOverrides != null) {
HashMap<String, String> propMap = new HashMap<String, String>();
AttributeOverride[] aoArray = attrOverrides.value();
for (int i = 0; i < aoArray.length; i++) {
String propName = aoArray[i].name();
String columnName = aoArray[i].column().name();
propMap.put(propName, columnName);
}
prop.getDeployEmbedded().putAll(propMap);
}
}
}