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

Bug 366386

Summary: CriteriaBuilder.select and multiselect are expected to throw IllegalArgumentException if more than one selection item uses the same alias
Product: z_Archived Reporter: Stephen DiMilla <stephen.dimilla>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: blocker    
Priority: P3 CC: lance.andersen, stephen.dimilla, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
proposed fix and test case none

Description Stephen DiMilla CLA 2011-12-12 07:32:32 EST
Build Identifier: eclipselink-2.3.0.v20110604-r9504

Using the entity:

@Entity
@Table(name="CUSTOMER_TABLE")
public class Customer implements java.io.Serializable
{

    // Instance variables
    private String id;
    private String name;
    public Customer()
    {
    }

    public Customer (String id, String name)
    {
    this.id = id;
    this.name = name;
    }
   @Id
    @Column(name="ID")
    public String getId() {
    return id;
    }
    public void setId(String v) {
    this.id = v;
    }

    @Column(name="NAME")
    public String getName() {
    return name;
    }
    public void setName(String v) {
    this.name = v;
    }
}
----------------------
Using the client code:


            CriteriaBuilder qbuilder = getEntityManagerFactory().getCriteriaBuilder();
            CriteriaQuery cquery = qbuilder.createQuery();
            Root<Customer> customer = cquery.from(Customer.class);

            System.out.println("Creating select using selection items with the same alias");
            try {
                cquery.select(qbuilder.array(customer.get("id").alias("SAMEALIAS"),
                        customer.get("name").alias("SAMEALIAS")));

                System.out.println("Did not thrown IllegalArgumentException");
                pass = false;
            } catch (IllegalArgumentException iae) {
                System.out.println("received expected IllegalArgumentException");
            } catch (Exception e) {
                pass = false;
                System.out.println("Received unexpected exception", e);
            }


----------------------
output:


[Creating select using selection items with the same alias
Did not thrown IllegalArgumentException


Reproducible: Always
Comment 1 Stephen DiMilla CLA 2011-12-12 07:42:52 EST
The following client code also has the same issue:

            CriteriaBuilder qbuilder = getEntityManagerFactory().getCriteriaBuilder();
            CriteriaQuery cquery = qbuilder.createQuery();
            Root<Customer> customer = cquery.from(Customer.class);

            System.out.println("Creating select using selection items with the same alias");
            try {
                 CompoundSelection<java.lang.Object[]> c = qbuilder.array(customer.get("id").alias("SAMEALIAS"),
                                                                                                  customer.get("name").alias("SAMEALIAS"));

                cquery.select(c);

                System.out.println("Did not thrown IllegalArgumentException");
                pass = false;
            } catch (IllegalArgumentException iae) {
                System.out.println("received expected IllegalArgumentException");
            } catch (Exception e) {
                pass = false;
                System.out.println("Received unexpected exception", e);
            }
Comment 2 Tom Ware CLA 2012-04-05 11:01:23 EDT
Updating target milestone.
Comment 3 Chris Delahunt CLA 2012-11-09 17:16:35 EST
Created attachment 223420 [details]
proposed fix and test case
Comment 4 Chris Delahunt CLA 2012-11-09 17:20:06 EST
*** Bug 366261 has been marked as a duplicate of this bug. ***
Comment 5 Chris Delahunt CLA 2012-11-12 16:16:38 EST
Fix checked into main
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:28:29 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink