Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfilion2012-05-10 17:26:39 +0000
committerpfilion2012-05-10 17:26:39 +0000
commit404f9a3a1182a77c1a783bbf2685bcb6a7f55684 (patch)
tree03aa43af4eabc34cb04eef11bceff25cd4f21216
parent446a1bc8bd59f5b642ade826af92eaf1704d60d6 (diff)
downloadwebtools.dali-404f9a3a1182a77c1a783bbf2685bcb6a7f55684.tar.gz
webtools.dali-404f9a3a1182a77c1a783bbf2685bcb6a7f55684.tar.xz
webtools.dali-404f9a3a1182a77c1a783bbf2685bcb6a7f55684.zip
Fix for bug#374145 - JPQL: Relationship mapping can't be traversed correctly
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMapping.java43
1 files changed, 40 insertions, 3 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMapping.java
index faebd4da75..cdf7276d26 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpql/JpaMapping.java
@@ -22,6 +22,7 @@ import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.RelationshipMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
@@ -95,6 +96,32 @@ final class JpaMapping implements IMapping {
};
}
+ private IType buildType() {
+
+ PersistentAttribute property = mapping.getPersistentAttribute();
+ String typeName = property.getTypeName();
+
+ // The attribute could be virtual, incorrectly specified in the orm.xml
+ if (typeName == null) {
+ return getTypeRepository().getTypeHelper().unknownType();
+ }
+
+ // For relationship mapping, make sure to check the target entity first
+ if (isRelationship()) {
+
+ String entityName = ((RelationshipMapping) mapping).getTargetEntity();
+
+ if (StringTools.stringIsNotEmpty(entityName)) {
+ IManagedType entity = getParent().getProvider().getManagedType(entityName);
+ if (entity != null) {
+ return entity.getType();
+ }
+ }
+ }
+
+ return getTypeRepository().getType(typeName);
+ }
+
private ITypeDeclaration buildTypeDeclaration() {
PersistentAttribute property = mapping.getPersistentAttribute();
@@ -124,7 +151,6 @@ final class JpaMapping implements IMapping {
*/
public IMappingType getMappingType() {
if (mappingType == null) {
- getTypeDeclaration();
mappingType = mappingType();
}
return mappingType;
@@ -149,8 +175,7 @@ final class JpaMapping implements IMapping {
*/
public IType getType() {
if (type == null) {
- PersistentAttribute property = mapping.getPersistentAttribute();
- type = getTypeRepository().getType(property.getTypeName());
+ type = buildType();
}
return type;
}
@@ -177,6 +202,18 @@ final class JpaMapping implements IMapping {
return attribute.getAnnotation(annotationType.getName()) != null;
}
+ public boolean isRelationship() {
+ switch (getMappingType()) {
+ case ELEMENT_COLLECTION:
+ case EMBEDDED_ID:
+ case MANY_TO_MANY:
+ case MANY_TO_ONE:
+ case ONE_TO_MANY:
+ case ONE_TO_ONE: return true;
+ default: return false;
+ }
+ }
+
private IMappingType mappingType() {
String type = mapping.getKey();

Back to the top