Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MapKeyJoinColumnName set to JoinColumn name in entity metadata

  • Loading branch information...
commit 5302cdea408d31fed06d70d66806d1bbbc66774c 1 parent 883585a
xamry authored
View
21 ...e/src/main/java/com/impetus/kundera/metadata/processor/relation/ManyToManyRelationMetadataProcessor.java
@@ -24,6 +24,9 @@
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.MapKeyClass;
+import javax.persistence.MapKeyJoinColumn;
+
+import org.apache.commons.lang.StringUtils;
import com.impetus.kundera.loader.MetamodelLoaderException;
import com.impetus.kundera.metadata.model.EntityMetadata;
@@ -86,8 +89,7 @@ public void addRelationIntoMetadata(Field relationField, EntityMetadata metadata
targetEntity = genericClasses.get(1);
}
- MapKeyClass mapKeyClassAnn = relationField.getAnnotation(MapKeyClass.class);
- //MapKeyJoinColumn mapKeyJoinColumnAnn = relationField.getAnnotation(MapKeyJoinColumn.class);
+ MapKeyClass mapKeyClassAnn = relationField.getAnnotation(MapKeyClass.class);
//Check for Map key class specified at annotation
if (mapKeyClass == null && mapKeyClassAnn != null && mapKeyClassAnn.value() != null && ! mapKeyClassAnn.value().getSimpleName().equals("void"))
@@ -137,6 +139,21 @@ else if (isJoinedByTable)
else if(isJoinedByMap)
{
relation.setMapKeyJoinClass(mapKeyClass);
+
+ MapKeyJoinColumn mapKeyJoinColumnAnn = relationField.getAnnotation(MapKeyJoinColumn.class);
+ if(mapKeyJoinColumnAnn != null)
+ {
+ String mapKeyJoinColumnName = mapKeyJoinColumnAnn.name();
+ if (!StringUtils.isEmpty(mapKeyJoinColumnName))
+ {
+ relation.setJoinColumnName(mapKeyJoinColumnName);
+ }
+ else
+ {
+ throw new InvalidEntityDefinitionException("It's mandatory to specify name attribute with @MapKeyJoinColumn annotation");
+ }
+ }
+
}
else if (relation.getMappedBy() == null || relation.getMappedBy().isEmpty())
{
Please sign in to comment.
Something went wrong with that request. Please try again.