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

Bug 366261

Summary: CriteriaQuery.multiselect() does not throw IllegalArgumentException if more than one selection item has the same assigned alias
Product: z_Archived Reporter: Stephen DiMilla <stephen.dimilla>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED DUPLICATE QA Contact:
Severity: blocker    
Priority: P3 CC: christopher.delahunt, lance.andersen, stephen.dimilla, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Stephen DiMilla CLA 2011-12-09 16:20:15 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 = em.getCriteriaBuilder();
 
       System.out.println("Testing multiselect selection[]");
        cquery = qbuilder.createTupleQuery();
        if (cquery != null) {
            System.out.println("Obtained Non-null Criteria Query");
            Root<Customer> customer = cquery.from(Customer.class);

            System.out.println("Creating multiselect using selection array of items with the same alias");
            Selection[] selection = {customer.get("id").alias("SAMEALIAS"), customer.get("name").alias("SAMEALIAS")};

            try {
                cquery.multiselect(selection);
                System.out.println("Did not thrown IllegalArgumentException");
            } catch (IllegalArgumentException iae) {
                System.out.println("received expected IllegalArgumentException");
            } catch (Exception e) {
                System.out.println("Received unexpected exception", e);
            }
        }
        System.out.println("Testing multiselect List");
        cquery = qbuilder.createTupleQuery();
        if (cquery != null) {
            System.out.println("Obtained Non-null Criteria Query");
            Root<Customer> customer = cquery.from(Customer.class);

            System.out.println("Creating multiselect using selection items with the same alias");
            try {
                List list = new ArrayList();
                list.add(customer.get("id").alias("SAMEALIAS"));
                list.add(customer.get("name").alias("SAMEALIAS"));

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

---------
output:
Testing multiselect selection[]
Obtained Non-null Criteria Query
Creating multiselect using selection array of items with the same alias
Did not thrown IllegalArgumentException
Testing multiselect List
Obtained Non-null Criteria Query
Creating multiselect using selection items with the same alias
Did not thrown IllegalArgumentException

Reproducible: Always
Comment 1 Tom Ware CLA 2012-04-05 11:01:19 EDT
Updating target milestone.
Comment 2 Chris Delahunt CLA 2012-11-09 17:20:06 EST

*** This bug has been marked as a duplicate of bug 366386 ***
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:16:46 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:33:48 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink