Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins')
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java47
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/JavaEntityPrimaryKeyJoinColumnValidator.java40
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java1
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java5
7 files changed, 69 insertions, 68 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties
index 13f8f623ae..eda9209d10 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation.properties
@@ -58,12 +58,13 @@ ENTITY_NAME_MISSING=The given name of the entity \"{0}\" is empty
ENTITY_NO_PK=The entity has no primary key attribute defined
ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED=A primary key attribute should only be defined on the root entity or a mapped superclass
ENTITY_NON_ROOT_ID_CLASS_SPECIFIED=An ID class should only be defined on the root entity or a mapped superclass
-TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class \"{0}\" is annotated, but not listed in the persistence.xml file
-TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class \"{0}\" is managed, but is not listed in the persistence.xml file
-PERSISTENT_TYPE_DUPLICATE_CLASS=Duplicate class \"{0}\" found in mapping files. This configuration is not supported by the tooling and may result in invalid error messages.
MANAGED_TYPE_UNRESOLVED_CLASS=Class \"{0}\" cannot be resolved
MANAGED_TYPE_UNSPECIFIED_CLASS=Unspecified class
+ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED=Root entity should not have primary key join column defined
+PERSISTENT_TYPE_DUPLICATE_CLASS=Duplicate class \"{0}\" found in mapping files. This configuration is not supported by the tooling and may result in invalid error messages.
TARGET_NOT_AN_EMBEDDABLE={0} is not mapped as an embeddable
+TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class \"{0}\" is annotated, but not listed in the persistence.xml file
+TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class \"{0}\" is managed, but is not listed in the persistence.xml file
TYPE_MAPPING_CLASS_MISSING_NO_ARG_CONSTRUCTOR=The Java class for mapped type \"{0}\" must define a non-private zero-argument constructor
TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR=The Java class for mapped type \"{0}\" has a private zero-argument constructor; it must be public or protected
TYPE_MAPPING_FINAL_CLASS=The Java class for mapped type \"{0}\" is final
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties
index 57d8fb42d6..b7c0b5fdf3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpt_jpa_core_validation_description.properties
@@ -53,12 +53,13 @@ ENTITY_NAME_MISSING=Entity name is empty
ENTITY_NO_PK=Entity has no primary key
ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED=Primary key attribute should only be defined on the root entity or a mapped superclass
ENTITY_NON_ROOT_ID_CLASS_SPECIFIED=ID class should only be defined on the root entity or a mapped superclass
-TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class is annotated, but is not listed in the persistence.xml file
-TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class is managed, but is not listed in the persistence.xml file
-PERSISTENT_TYPE_DUPLICATE_CLASS=Duplicate ORM class
MANAGED_TYPE_UNRESOLVED_CLASS=Class in orm.xml cannot be resolved to a java class
MANAGED_TYPE_UNSPECIFIED_CLASS=Class is unspecified in orm.xml
+PERSISTENT_TYPE_DUPLICATE_CLASS=Duplicate ORM class
+ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED=Root entity should not have primary key join column defined
TARGET_NOT_AN_EMBEDDABLE=Target type of an embedded mapping is not an embeddable
+TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class is annotated, but is not listed in the persistence.xml file
+TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML=Class is managed, but is not listed in the persistence.xml file
TYPE_MAPPING_CLASS_MISSING_NO_ARG_CONSTRUCTOR=Mapped Java class has no no-arg constructor
TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR=Mapped Java class has a private no-arg constructor
TYPE_MAPPING_FINAL_CLASS=Mapped Java class is final
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java
index b6850e27b8..1a1a1bac03 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java
@@ -80,13 +80,13 @@ import org.eclipse.jpt.jpa.core.internal.jpa1.context.AssociationOverrideValidat
import org.eclipse.jpt.jpa.core.internal.jpa1.context.AttributeOverrideColumnValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.AttributeOverrideValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.DiscriminatorColumnValidator;
+import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityPrimaryKeyJoinColumnValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityTableDescriptionProvider;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.GenericEntityPrimaryKeyValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.JoinTableTableDescriptionProvider;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.MappedSuperclassOverrideDescriptionProvider;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.SecondaryTableValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.TableValidator;
-import org.eclipse.jpt.jpa.core.internal.jpa1.context.java.JavaEntityPrimaryKeyJoinColumnValidator;
import org.eclipse.jpt.jpa.core.internal.resource.java.NullPrimaryKeyJoinColumnAnnotation;
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaAssociationOverrideContainer2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaAttributeOverrideContainer2_0;
@@ -517,16 +517,15 @@ public abstract class AbstractJavaEntity
}
public void convertDefaultPrimaryKeyJoinColumnsToSpecified() {
- if (this.defaultPrimaryKeyJoinColumn == null) {
- throw new IllegalStateException("default PK join column is null"); //$NON-NLS-1$
- }
- // Add a PK join column by creating a specified one using the default one
- String columnName = this.defaultPrimaryKeyJoinColumn.getDefaultName();
- String referencedColumnName = this.defaultPrimaryKeyJoinColumn.getDefaultReferencedColumnName();
-
- SpecifiedPrimaryKeyJoinColumn pkJoinColumn = this.addSpecifiedPrimaryKeyJoinColumn(0);
- pkJoinColumn.setSpecifiedName(columnName);
- pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName);
+ // This is for root entities which have no default PK join column
+ SpecifiedPrimaryKeyJoinColumn pkJoinColumn = this.addSpecifiedPrimaryKeyJoinColumn(0);
+ // Add a PK join column by creating a specified one using the default one
+ if (this.defaultPrimaryKeyJoinColumn != null) {
+ String columnName = this.defaultPrimaryKeyJoinColumn.getDefaultName();
+ String referencedColumnName = this.defaultPrimaryKeyJoinColumn.getDefaultReferencedColumnName();
+ pkJoinColumn.setSpecifiedName(columnName);
+ pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName);
+ }
}
public void clearSpecifiedPrimaryKeyJoinColumns() {
@@ -626,7 +625,7 @@ public abstract class AbstractJavaEntity
}
protected boolean buildsDefaultPrimaryKeyJoinColumn() {
- return ! this.hasSpecifiedPrimaryKeyJoinColumns();
+ return ! this.isRootEntity() && ! this.hasSpecifiedPrimaryKeyJoinColumns();
}
protected JavaSpecifiedPrimaryKeyJoinColumn buildDefaultPrimaryKeyJoinColumn() {
@@ -1222,9 +1221,7 @@ public abstract class AbstractJavaEntity
secondaryTable.validate(messages, reporter);
}
this.validateInheritance(messages, reporter);
- for (JavaSpecifiedPrimaryKeyJoinColumn pkJoinColumn : this.getPrimaryKeyJoinColumns()) {
- pkJoinColumn.validate(messages, reporter);
- }
+ this.validatePrimaryKeyJoinColumns(messages, reporter);
this.generatorContainer.validate(messages, reporter);
this.queryContainer.validate(messages, reporter);
this.attributeOverrideContainer.validate(messages, reporter);
@@ -1232,6 +1229,24 @@ public abstract class AbstractJavaEntity
this.validateEntityName(messages);
}
+ protected void validatePrimaryKeyJoinColumns(List<IMessage> messages, IReporter reporter) {
+ if (this.getPrimaryKeyJoinColumnsSize() > 0) {
+ if (this.getParentEntity() == null) {
+ messages.add(
+ this.buildValidationMessage(
+ this.getMappingAnnotation().getNameTextRange(),
+ JptJpaCoreValidationMessages.ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED,
+ this.getPersistentType().getName()
+ )
+ );
+ } else {
+ for (JavaSpecifiedPrimaryKeyJoinColumn pkJoinColumn : this.getPrimaryKeyJoinColumns()) {
+ pkJoinColumn.validate(messages, reporter);
+ }
+ }
+ }
+ }
+
@Override
public boolean validatesAgainstDatabase() {
return super.validatesAgainstDatabase() && ! this.isAbstractTablePerClass();
@@ -1585,7 +1600,7 @@ public abstract class AbstractJavaEntity
}
public JpaValidator buildColumnValidator(NamedColumn column) {
- return new JavaEntityPrimaryKeyJoinColumnValidator((BaseJoinColumn) column, this, AbstractJavaEntity.this);
+ return new EntityPrimaryKeyJoinColumnValidator((BaseJoinColumn) column, this);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java
index 79c68fec83..b2e6e8401a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java
@@ -764,6 +764,11 @@ public abstract class AbstractOrmEntity<X extends XmlEntity>
}
public void convertDefaultPrimaryKeyJoinColumnsToSpecified() {
+ // This is necessary for root entities which have no default PK join column
+ if (this.getPrimaryKeyJoinColumnsSize() == 0) {
+ this.addSpecifiedPrimaryKeyJoinColumn();
+ }
+
for (PrimaryKeyJoinColumn defaultJoinColumn : this.getDefaultPrimaryKeyJoinColumns()) {
String columnName = defaultJoinColumn.getName();
String referencedColumnName = defaultJoinColumn.getReferencedColumnName();
@@ -868,7 +873,7 @@ public abstract class AbstractOrmEntity<X extends XmlEntity>
if (this.javaPrimaryKeyJoinColumnsWillBeDefaults()) {
// specified => java
this.initializeVirtualPrimaryKeyJoinColumns();
- } else {
+ } else if (this.getParentEntity() != null) {
// specified => default
this.addDefaultPrimaryKeyJoinColumn();
}
@@ -1673,9 +1678,7 @@ public abstract class AbstractOrmEntity<X extends XmlEntity>
secondaryTable.validate(messages, reporter);
}
this.validateInheritance(messages, reporter);
- for (OrmSpecifiedPrimaryKeyJoinColumn pkJoinColumn : this.getSpecifiedPrimaryKeyJoinColumns()) {
- pkJoinColumn.validate(messages, reporter);
- }
+ this.validatePrimaryKeyJoinColumns(messages, reporter);
this.attributeOverrideContainer.validate(messages, reporter);
this.associationOverrideContainer.validate(messages, reporter);
this.generatorContainer.validate(messages, reporter);
@@ -1684,6 +1687,25 @@ public abstract class AbstractOrmEntity<X extends XmlEntity>
this.idClassReference.validate(messages, reporter);
}
+ protected void validatePrimaryKeyJoinColumns(List<IMessage> messages, IReporter reporter) {
+ if (this.getPrimaryKeyJoinColumnsSize() > 0) {
+ if (this.getParentEntity() == null) {
+ messages.add(
+ this.buildValidationMessage(
+ this.getNameTextRange(),
+ JptJpaCoreValidationMessages.ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED,
+ this.getPersistentType().getName()
+ )
+ );
+ } else {
+ for (OrmSpecifiedPrimaryKeyJoinColumn pkJoinColumn : this.getSpecifiedPrimaryKeyJoinColumns()) {
+ pkJoinColumn.validate(messages, reporter);
+ }
+ }
+ }
+
+ }
+
protected void validateEntityName(List<IMessage> messages) {
if (StringTools.isBlank(this.getName())){
messages.add(
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/JavaEntityPrimaryKeyJoinColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/JavaEntityPrimaryKeyJoinColumnValidator.java
deleted file mode 100644
index c2e3236172..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/JavaEntityPrimaryKeyJoinColumnValidator.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
-
-import java.util.List;
-import org.eclipse.jpt.jpa.core.context.BaseJoinColumn;
-import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaEntity;
-import org.eclipse.jpt.jpa.core.internal.jpa1.context.EntityPrimaryKeyJoinColumnValidator;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
-
-public class JavaEntityPrimaryKeyJoinColumnValidator
- extends EntityPrimaryKeyJoinColumnValidator
-{
- protected final AbstractJavaEntity entity;
-
- public JavaEntityPrimaryKeyJoinColumnValidator(
- BaseJoinColumn column,
- BaseJoinColumn.ParentAdapter parentAdapter,
- AbstractJavaEntity entity) {
- super(column, parentAdapter);
- this.entity = entity;
- }
-
- @Override
- protected void validateJoinColumnName(List<IMessage> messages) {
- // Based on the spec., the PrimaryKeyJoinColumn annotation is really only meaningful when
- // applying on an entity subclass so we only validate it when an entity is a descendant or an entity
- // has specified primary key join columns
- if (this.entity.isDescendant() || this.entity.getSpecifiedPrimaryKeyJoinColumnsSize() > 0) {
- super.validateJoinColumnName(messages);
- }
- }
-} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java
index e64f4de492..7272c06594 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/validation/JptJpaCoreValidationMessages.java
@@ -72,6 +72,7 @@ public class JptJpaCoreValidationMessages {
public static ValidationMessage TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML;
public static ValidationMessage MANAGED_TYPE_UNRESOLVED_CLASS;
public static ValidationMessage MANAGED_TYPE_UNSPECIFIED_CLASS;
+ public static ValidationMessage ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED;
public static ValidationMessage TARGET_NOT_AN_EMBEDDABLE;
public static ValidationMessage TYPE_MAPPING_CLASS_MISSING_NO_ARG_CONSTRUCTOR;
public static ValidationMessage TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java
index 0573bc8e29..77eba68c81 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/prefs/JpaProblemSeveritiesPage.java
@@ -117,10 +117,11 @@ public class JpaProblemSeveritiesPage
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.ENTITY_NO_PK);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED); //3.0 M7
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.ENTITY_NON_ROOT_ID_CLASS_SPECIFIED); //3.0 M7
- this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML);
- this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.MANAGED_TYPE_UNRESOLVED_CLASS);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.MANAGED_TYPE_UNSPECIFIED_CLASS);
+ this.addLabeledCombo(parent, JptJpaCoreValidationMessages.ROOT_ENTITY_HAS_PK_JOIN_COLUMN_DEFINED);
+ this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_ANNOTATED_BUT_NOT_LISTED_IN_PERSISTENCE_XML);
+ this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MANAGED_BUT_NOT_LISTED_IN_PERSISTENCE_XML);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MAPPING_CLASS_MISSING_NO_ARG_CONSTRUCTOR);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR);
this.addLabeledCombo(parent, JptJpaCoreValidationMessages.TYPE_MAPPING_FINAL_CLASS);

Back to the top