Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 172235 Details for
Bug 300458
EclipseLink should throw a more specific exception than NPE
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed changes
patch300458.patch (text/plain), 19.46 KB, created by
Guy Pelletier
on 2010-06-18 12:55:25 EDT
(
hide
)
Description:
Proposed changes
Filename:
MIME Type:
Creator:
Guy Pelletier
Created:
2010-06-18 12:55:25 EDT
Size:
19.46 KB
patch
obsolete
>Index: foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/localization/i18n/LoggingLocalizationResource.java >=================================================================== >--- foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/localization/i18n/LoggingLocalizationResource.java (revision 7632) >+++ foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/localization/i18n/LoggingLocalizationResource.java (working copy) >@@ -276,6 +276,8 @@ > { "metadata_warning_ignore_fetch_group", "Ignoring the fetch groups specified on class [{0}] for the entity [{1}] since weaving is not enabled and the entity class does not implement the FetchGroupTracker interface." }, > { "metadata_warning_ignore_mapping_metadata", "Ignoring the javax.persistence metadata applied to the attribute [{0}] from class [{1}]. javax.persistence metadata is ignored on fields or properties that are transient, static or abstract." }, > >+ { "metadata_warning_multiple_id_fields_without_id_class", "You have specified multiple ids for the entity class [{0}] without specifying an @IdClass. By doing this you may lose the ability to find by identity, distributed cache support etc. Note: You may howvever use entity manager find operations by passing a list of primary key fields. Else, you will have to use JPQL queries to read your entities. For other id options see @PrimaryKey." }, >+ > { "annotation_warning_ignore_annotation", "Ignoring the annotation [{0}] on the element [{1}] because of an XML metadata-complete setting of true for this class." }, > { "annotation_warning_ignore_private_owned", "Ignoring @PrivateOwned on element [{1}] within entity class [{0}]. A @PrivateOwned can only be used with a @OneToOne, @OneToMany and @VariableOneToOne. Also note, private ownership is implied with a @BasicCollection and @BasicMap." }, > { "annotation_warning_ignore_return_insert", "Ignoring the @ReturnInsert on the element [{0}]. A @ReturnInsert is only supported with a basic mapping." }, >Index: jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/inherited/Bylaw.java >=================================================================== >--- jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/inherited/Bylaw.java (revision 0) >+++ jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/inherited/Bylaw.java (revision 0) >@@ -0,0 +1,46 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Oracle. All rights reserved. >+ * This program and the accompanying materials are made available under the >+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 >+ * which accompanies this distribution. >+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html >+ * and the Eclipse Distribution License is available at >+ * http://www.eclipse.org/org/documents/edl-v10.php. >+ * >+ * Contributors: >+ * 06/18/2010-2.2 Guy Pelletier >+ * - 300458: EclispeLink should throw a more specific exception than NPE >+ ******************************************************************************/ >+package org.eclipse.persistence.testing.models.jpa.inherited; >+ >+import javax.persistence.Column; >+import javax.persistence.GeneratedValue; >+import javax.persistence.Id; >+import javax.persistence.MappedSuperclass; >+ >+@MappedSuperclass >+public class Bylaw { >+ public String city; >+ public int number; >+ >+ @Id >+ public String getCity() { >+ return city; >+ } >+ >+ @Id >+ @Column(name="NUMB") >+ @GeneratedValue >+ public int getNumber() { >+ return number; >+ } >+ >+ public void setCity(String city) { >+ this.city = city; >+ } >+ >+ public void setNumber(int number) { >+ this.number = number; >+ } >+ >+} >Index: jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/inherited/InheritedTableManager.java >=================================================================== >--- jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/inherited/InheritedTableManager.java (revision 7632) >+++ jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/inherited/InheritedTableManager.java (working copy) >@@ -31,6 +31,8 @@ > * - 299893: @MapKeyClass does not work with ElementCollection > * 02/18/2010-2.0.2 Guy Pelletier > * - 294803: @Column(updatable=false) has no effect on @Basic mappings >+ * 06/18/2010-2.2 Guy Pelletier >+ * - 300458: EclispeLink should throw a more specific exception than NPE > ******************************************************************************/ > package org.eclipse.persistence.testing.models.jpa.inherited; > >@@ -88,10 +90,10 @@ > addTableDefinition(build_COMMITTEE_Table()); > addTableDefinition(build_SERIALNUMBER_Table()); > addTableDefinition(build_TELEPHONE_NUMBER_Table()); >- > addTableDefinition(build_LOCATION_Table()); > > addTableDefinition(build_BC_LOOKUP_Table()); >+ addTableDefinition(build_NOISE_BYLAW_Table()); > } > > public static TableDefinition build_ALPINE_Table() { >@@ -837,6 +839,43 @@ > return table; > } > >+ public static TableDefinition build_NOISE_BYLAW_Table() { >+ TableDefinition table = new TableDefinition(); >+ table.setName("JPA_NOISY"); >+ >+ FieldDefinition CITY_field = new FieldDefinition(); >+ CITY_field.setName("CITY"); >+ CITY_field.setTypeName("VARCHAR"); >+ CITY_field.setSize(25); >+ CITY_field.setIsPrimaryKey(true); >+ CITY_field.setUnique(false); >+ CITY_field.setIsIdentity(false); >+ CITY_field.setShouldAllowNull(false); >+ table.addField(CITY_field); >+ >+ FieldDefinition NUMB_field = new FieldDefinition(); >+ NUMB_field.setName("NUMB"); >+ NUMB_field.setTypeName("NUMERIC"); >+ NUMB_field.setSize(15); >+ NUMB_field.setIsPrimaryKey(true); >+ NUMB_field.setUnique(false); >+ NUMB_field.setIsIdentity(false); >+ NUMB_field.setShouldAllowNull(false); >+ table.addField(NUMB_field); >+ >+ FieldDefinition DESCRIP_field = new FieldDefinition(); >+ DESCRIP_field.setName("DESCRIP"); >+ DESCRIP_field.setTypeName("VARCHAR"); >+ DESCRIP_field.setSize(100); >+ DESCRIP_field.setIsPrimaryKey(false); >+ DESCRIP_field.setUnique(false); >+ DESCRIP_field.setIsIdentity(false); >+ DESCRIP_field.setShouldAllowNull(true); >+ table.addField(DESCRIP_field); >+ >+ return table; >+ } >+ > public static TableDefinition build_EXPERT_BEER_CONSUMER_ACCLAIMS_Table() { > TableDefinition table = new TableDefinition(); > table.setName("EXPERT_CONSUMER_ACCLAIMS"); >Index: jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/inherited/NoiseBylaw.java >=================================================================== >--- jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/inherited/NoiseBylaw.java (revision 0) >+++ jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/inherited/NoiseBylaw.java (revision 0) >@@ -0,0 +1,33 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Oracle. All rights reserved. >+ * This program and the accompanying materials are made available under the >+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 >+ * which accompanies this distribution. >+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html >+ * and the Eclipse Distribution License is available at >+ * http://www.eclipse.org/org/documents/edl-v10.php. >+ * >+ * Contributors: >+ * 06/18/2010-2.2 Guy Pelletier >+ * - 300458: EclispeLink should throw a more specific exception than NPE >+ ******************************************************************************/ >+package org.eclipse.persistence.testing.models.jpa.inherited; >+ >+import javax.persistence.Column; >+import javax.persistence.Entity; >+import javax.persistence.Table; >+ >+@Entity >+@Table(name="JPA_NOISY") >+public class NoiseBylaw extends Bylaw { >+ public String description; >+ >+ @Column(name="DESCRIP") >+ public String getDescription() { >+ return description; >+ } >+ >+ public void setDescription(String description) { >+ this.description = description; >+ } >+} >Index: jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/inherited/InheritedModelJunitTest.java >=================================================================== >--- jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/inherited/InheritedModelJunitTest.java (revision 7632) >+++ jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/inherited/InheritedModelJunitTest.java (working copy) >@@ -27,6 +27,8 @@ > * - 249037: JPA 2.0 persisting list item index > * 02/18/2010-2.0.2 Guy Pelletier > * - 294803: @Column(updatable=false) has no effect on @Basic mappings >+ * 06/18/2010-2.2 Guy Pelletier >+ * - 300458: EclispeLink should throw a more specific exception than NPE > ******************************************************************************/ > package org.eclipse.persistence.testing.tests.jpa.inherited; > >@@ -62,6 +64,7 @@ > import org.eclipse.persistence.testing.models.jpa.inherited.Heineken; > import org.eclipse.persistence.testing.models.jpa.inherited.InheritedTableManager; > import org.eclipse.persistence.testing.models.jpa.inherited.Location; >+import org.eclipse.persistence.testing.models.jpa.inherited.NoiseBylaw; > import org.eclipse.persistence.testing.models.jpa.inherited.NoviceBeerConsumer; > import org.eclipse.persistence.testing.models.jpa.inherited.Official; > import org.eclipse.persistence.testing.models.jpa.inherited.OfficialEntry; >@@ -137,6 +140,7 @@ > suite.addTest(new InheritedModelJunitTest("testColumnUpdatableAndInsertable")); > suite.addTest(new InheritedModelJunitTest("testColumnUpdatableAndInsertableThroughQuery")); > suite.addTest(new InheritedModelJunitTest("testElementCollectionMapEmbeddable")); >+ suite.addTest(new InheritedModelJunitTest("testMultipleIdButNonIdClassEntity")); > > return suite; > } >@@ -149,6 +153,47 @@ > clearCache(); > } > >+ public void testMultipleIdButNonIdClassEntity() { >+ EntityManager em = createEntityManager(); >+ beginTransaction(em); >+ >+ NoiseBylaw noiseBylaw = new NoiseBylaw(); >+ int noiseBylawId = 0; >+ >+ try { >+ getServerSession().setLogLevel(0); >+ >+ noiseBylaw.setCity("Ottawa"); >+ noiseBylaw.setDescription("Can't mow your grass after 9PM!"); >+ em.persist(noiseBylaw); >+ noiseBylawId = noiseBylaw.getNumber(); >+ commitTransaction(em); >+ } catch (RuntimeException e) { >+ if (isTransactionActive(em)){ >+ rollbackTransaction(em); >+ } >+ >+ closeEntityManager(em); >+ fail("An exception was caught during create operation: [" + e.getMessage() + "]"); >+ } >+ >+ closeEntityManager(em); >+ >+ clearCache(); >+ em = createEntityManager(); >+ >+ // find by object entity will not work since there is no IdClass in >+ // this case so we will look it up through jpql >+ String jpqlString = "SELECT n FROM NoiseBylaw n WHERE n.number =" + noiseBylawId; >+ NoiseBylaw refreshedNoiseBylaw = (NoiseBylaw) em.createQuery(jpqlString).getSingleResult(); >+ >+ //Object refreshedNoiseBylaw = em.createNativeQuery("select * from JPA_NOISY e where e.numb = " + noiseBylawId).getSingleResult(); >+ //NoiseBylaw refreshedNoiseBylaw = em.find(NoiseBylaw.class, noiseBylawId); >+ assertTrue("The noise bylaw read back did not match the original", getServerSession().compareObjects(noiseBylaw, refreshedNoiseBylaw)); >+ >+ closeEntityManager(em); >+ } >+ > public void testBecksBeerConsumer() { > EntityManager em = createEntityManager(); > beginTransaction(em); >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/EntityAccessor.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/EntityAccessor.java (revision 7632) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/EntityAccessor.java (working copy) >@@ -63,6 +63,8 @@ > * - 313401: shared-cache-mode defaults to NONE when the element value is unrecognized > * 06/14/2010-2.2 Guy Pelletier > * - 264417: Table generation is incorrect for JoinTables in AssociationOverrides >+ * 06/18/2010-2.2 Guy Pelletier >+ * - 300458: EclispeLink should throw a more specific exception than NPE > ******************************************************************************/ > package org.eclipse.persistence.internal.jpa.metadata.accessors.classes; > >@@ -1366,6 +1368,13 @@ > if (getDescriptor().pkClassWasNotValidated()) { > throw ValidationException.invalidCompositePKSpecification(getJavaClass(), getDescriptor().getPKClassName()); > } >+ >+ // Log a warning to the user that they have specified multiple id >+ // fields without an id class specification. If they are using a >+ // @PrimaryKey specification don't issue the warning. >+ if (! getDescriptor().hasPKClass() && ! getDescriptor().hasPrimaryKey()) { >+ getLogger().logWarningMessage(MetadataLogger.MULTIPLE_ID_FIELDS_WITHOUT_ID_CLASS, getJavaClassName()); >+ } > } else { > // Descriptor has a single primary key. Validate an id > // attribute was found, unless we are an inheritance subclass >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataDescriptor.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataDescriptor.java (revision 7632) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataDescriptor.java (working copy) >@@ -66,6 +66,8 @@ > * - 315195: Add new property to avoid reading XML during the canonical model generation > * 06/14/2010-2.2 Guy Pelletier > * - 264417: Table generation is incorrect for JoinTables in AssociationOverrides >+ * 06/18/2010-2.2 Guy Pelletier >+ * - 300458: EclispeLink should throw a more specific exception than NPE > ******************************************************************************/ > package org.eclipse.persistence.internal.jpa.metadata; > >@@ -131,6 +133,7 @@ > private boolean m_hasCustomizer; > private boolean m_hasReadOnly; > private boolean m_hasCopyPolicy; >+ private boolean m_hasPrimaryKey; > > // Default access methods are used for VIRTUAL mapping attributes when > // the attributes do not specify their own access methods. >@@ -199,6 +202,7 @@ > m_hasCustomizer = false; > m_hasReadOnly = false; > m_hasCopyPolicy = false; >+ m_hasPrimaryKey = false; > m_isCascadePersist = false; > m_ignoreAnnotations = false; > m_ignoreDefaultMappings = false; >@@ -1079,6 +1083,15 @@ > public boolean hasCopyPolicy() { > return m_hasCopyPolicy; > } >+ >+ /** >+ * INTERNAL: >+ * Indicates that a PrimaryKey annotation or primary-key element has been >+ * processed for this descriptor. >+ */ >+ public boolean hasPrimaryKey() { >+ return m_hasPrimaryKey; >+ } > > /** > * INTERNAL: >@@ -1471,6 +1484,15 @@ > > /** > * INTERNAL: >+ * Indicates that we have processed a PrimaryKey annotation or primary-key >+ * xml element. >+ */ >+ public void setHasPrimaryKey() { >+ m_hasPrimaryKey = true; >+ } >+ >+ /** >+ * INTERNAL: > * Indicates that we have processed a change tracking annotation or change > * tracking xml element. > */ >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataLogger.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataLogger.java (revision 7632) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataLogger.java (working copy) >@@ -27,6 +27,8 @@ > * - 277039: JPA 2.0 Cache Usage Settings > * 01/19/2010-2.1 Guy Pelletier > * - 211322: Add fetch-group(s) support to the EclipseLink-ORM.XML Schema >+ * 06/18/2010-2.2 Guy Pelletier >+ * - 300458: EclispeLink should throw a more specific exception than NPE > ******************************************************************************/ > package org.eclipse.persistence.internal.jpa.metadata; > >@@ -105,7 +107,9 @@ > public static final String IGNORE_FETCH_GROUP = "metadata_warning_ignore_fetch_group"; > public static final String IGNORE_MAPPING_METADATA = "metadata_warning_ignore_mapping_metadata"; > >+ public static final String MULTIPLE_ID_FIELDS_WITHOUT_ID_CLASS = "metadata_warning_multiple_id_fields_without_id_class"; > >+ > /*************************************************************************/ > /* GENERIC DEFAULT MESSSAGES */ > /*************************************************************************/ >@@ -239,6 +243,8 @@ > addContextString(IGNORE_FETCH_GROUP); > addContextString(IGNORE_MAPPING_METADATA); > >+ addContextString(MULTIPLE_ID_FIELDS_WITHOUT_ID_CLASS); >+ > // Generic default messages that could apply to XML and annotation > // configurations. > addContextString(ACCESS_TYPE); >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/PrimaryKeyMetadata.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/PrimaryKeyMetadata.java (revision 7632) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/PrimaryKeyMetadata.java (working copy) >@@ -11,6 +11,8 @@ > * James Sutherland - initial impl > * 04/27/2010-2.1 Guy Pelletier > * - 309856: MappedSuperclasses from XML are not being initialized properly >+ * 06/18/2010-2.2 Guy Pelletier >+ * - 300458: EclispeLink should throw a more specific exception than NPE > ******************************************************************************/ > package org.eclipse.persistence.internal.jpa.metadata; > >@@ -118,6 +120,8 @@ > * Process the meta-data, configure primary key and idValidation in descriptor. > */ > public void process(MetadataDescriptor descriptor) { >+ descriptor.setHasPrimaryKey(); >+ > if (m_validation != null) { > descriptor.getClassDescriptor().setIdValidation(IdValidation.valueOf(m_validation)); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 300458
:
156900
|
172235
|
172236