Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 336596

Summary: java.util.NoSuchElementException when using @ElementCollection for enum in Embeddable
Product: z_Archived Reporter: darren
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: michael.f.obrien, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description darren CLA 2011-02-08 05:08:12 EST
Build Identifier: eclipselink-2.1.2

Firstly, this has been reported similarly at: 

Bug 298830 - @ElementCollection from embeddable object 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=298830,

and was claimed to be fixed, but the examples there do not use an enum in the ElementCollection, they use a String, perhaps that makes a difference.

I have an embeddable Permissions class with an @ElementCollection that is a List of enum Role:

@Embeddable
public class Permissions implements Serializable {

    private List<Role> doShowForRoles = new ArrayList<Role>(); //!
    //2011-02-07 Webel: not sure why not otherwise initialized !
    //need to avoid NullPointerException in add/remove ops.

    @ElementCollection
    public List<Role> getDoShowForRoles() {
        return doShowForRoles;
    }
    public void setDoShowForRoles(List<Role> doShowForRoles) {
        this.doShowForRoles = doShowForRoles;
    }

    public boolean addDoShowForRoles(Role role) {
        if (getDoShowForRoles().contains(role)) return false; //TODO warn
        return getDoShowForRoles().add(role);
    }

    public boolean removeDoShowForRoles(Role role) {
        return getDoShowForRoles().remove(role);
    }
}

(As you can see from the comments I also have a problem with initialization of the list, not sure whether this is at all related.)

Reproducible: Always

Steps to Reproduce:
1. Create an enum TheEnum

2. Create an @Embeddable TheEmbeddable with an @ElementCollection property List<TheEnum> getTheEnums().

3. Use the @Embeddable as an @Embedded property getTheEmbeddable() in an @Entity.

Run your application to get:

Internal Exception: java.util.NoSuchElementException
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:991)

As far as I'm concerned this is a major feature break, since the JavaEE6 specs make it clear that one should be able to handle this. From the JavaEE6 tutorial:

"Embeddable classes may themselves use other embeddable classes to represent their state. They may also contain collections of basic Java programming language types, or other embeddable classes. Embeddable classes may also contain relationships to other entities or collections of entities."
Comment 1 darren CLA 2011-02-08 05:18:31 EST
As far as I can tell this happens for EclipseLink versions 2.0.1 and 2.1.2 (except that 2.1.2 hits other problems first, such as not permitting my custom property annotations applied to a @Transient property, which I have to comment out to avoid: 'Mapping annotations cannot be applied to fields or properties that have a @Transient specified.').
Comment 2 darren CLA 2011-02-09 00:28:31 EST
I tried EclipseLink2.2.0RC4 with:

- jlib/jpa/javax.persistence_2.0.3.v201010191057.jar

- jlib/eclipselink.jar

(No moxy or sdo.)

I get the same error, I don't understand the versioning in the output:

SEVERE: Exception while preparing the app
javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [greendeskPU] failed.
Internal Exception: java.util.NoSuchElementException

Q1: How does 'Eclipse Persistence Services - 2.0.1.v20100213-r6600' relate to 
javax.persistence_2.0.3.v201010191057.jar and the "2.2.0RC"-ness of the EclipseLink2.2.0RC4 ?

Q2: Does this indicate something is wrong with my libraries (in Netbeans6.9.1 I uninstalled EclipseLink2.0.1 in favour of EclipseLink2.2.0RC4, however there might be a problem with referencing older EclipseLink libraries.
Comment 3 darren CLA 2011-02-09 01:22:25 EST
> I get the same error, I don't understand the versioning in the output:
> 
> SEVERE: Exception while preparing the app
> javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse
> Persistence Services - 2.0.1.v20100213-r6600): ..
..
> Q2: Does this indicate something is wrong with my libraries (in Netbeans6.9.1 I
> uninstalled EclipseLink2.0.1 in favour of EclipseLink2.2.0RC4, however there
> might be a problem with referencing older EclipseLink libraries.

Yes, it did. I had the glassfish3.0.1 eclipselink jars under glassfish/modules (as well as in Netbeans IDE); I moved them out of glassfish (including javax.persistence.jar) and copied back in just javax.persistence_2.0.3.v201010191057.jar (from EclipseLink2.2.0RC4).

I restarted glassfish, and my application runs with a new error (but at least it shows the expected version):

Exception [EclipseLink-68] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The value of an aggregate in object theObject is null.
Comment 4 Tom Ware CLA 2011-02-10 09:30:47 EST
The javax.persistence libraries and eclipselink libraries are versioned separately.

javax.persistence holds the JPA specification classes.  2.0.0 was the original implementation and each incremental release contains one or more bug fixes to the implementation classes within that library since the original implementation was releases.  (i.e. 2.0.3 contains several bug fixes to the classes released to support the original specification) In general, you should use the most recent version of these classes available and they should be compatible with any EclipseLink version that supports JPA 2.0.

EclipseLink 2.0.1.v20100213-r6600 is the version of EclipseLink that shipped with your GlassFish version.  2.2.0.v20110202-r8913 is our 2.2 release.  The official release will quite soon, but those are our final EclipseLink 2.2 bits.
Comment 5 Tom Ware CLA 2011-02-10 09:31:50 EST
BTW: PLease vote for the bugs you consider important.  Community votes are one of the main criteria we use to determine when to fix bugs.
Comment 6 darren CLA 2011-02-13 19:50:56 EST
(In reply to comment #4)
> The javax.persistence libraries and eclipselink libraries are versioned
> separately. ..
Thanks tom for this clarification, have read and understood, am now using EclipseLink 2.2.0.v20110202-r8913 (a.k.a.RC4) with @ElementCollection in Embeddable with success, and have understood how to better coordinate javax.persistence libraries and eclipselink libraries between glassfish and my IDE netbeans. As far as I can tell this is fixed in EclipseLink 2.2.0.v20110202-r8913, darren
Comment 7 darren CLA 2011-02-13 19:53:32 EST
(In reply to comment #3)
> I restarted glassfish, and my application runs with a new error (but at least
> it shows the expected version):
> 
> Exception [EclipseLink-68] (Eclipse Persistence Services -
> 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DescriptorException
> Exception Description: The value of an aggregate in object theObject is null.

This was because the embeddable field 'permissions' was not correctly initialized, this is now also working correctly, thanks, darren
Comment 8 Tom Ware CLA 2011-02-14 09:24:18 EST
Are there any remaining issues related to this bug in EclipseLink 2.2?
Comment 9 darren CLA 2011-02-14 13:34:36 EST
(In reply to comment #8)
> Are there any remaining issues related to this bug in EclipseLink 2.2?
Not as far as I can tell. Have set resolved.

BTW as I'm new to Eclipse Bugzilla, could you please refer to information on whether in such cases:
(A) I (the bug reported) should close this bug report (set as resolved, and if so, how I should indicate the "fixed in" version EclipseLink 2.2RC4),
OR (B) whether somebody more "official" from the project should close it (set a resolved) ? 

Thanks, Darren
Comment 10 Tom Ware CLA 2011-02-14 13:45:12 EST
Setting target to 2.2.0 - based on comments above.

If you know that a bug you have filed is fixed and know the version, please feel free to close it.  If you were not the filer, it is best to leave it open and add comments asking someone else to close it.
Comment 11 Eclipse Webmaster CLA 2022-06-09 10:15:06 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 12 Eclipse Webmaster CLA 2022-06-09 10:31:52 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink