Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366386 - CriteriaBuilder.select and multiselect are expected to throw IllegalArgumentException if more than one selection item uses the same alias
Summary: CriteriaBuilder.select and multiselect are expected to throw IllegalArgumentE...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 blocker (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 366261 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-12-12 07:32 EST by Stephen DiMilla CLA
Modified: 2022-06-09 10:28 EDT (History)
3 users (show)

See Also:


Attachments
proposed fix and test case (9.52 KB, patch)
2012-11-09 17:16 EST, Chris Delahunt CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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