Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366436 - Query.getLockMode() does not throw IllegalStateException when the query is found not to be a Java Persistence query language SELECT query or a Criteria API query
Summary: Query.getLockMode() does not throw IllegalStateException when the query is fo...
Status: CLOSED INVALID
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:
Depends on:
Blocks:
 
Reported: 2011-12-12 12:13 EST by Stephen DiMilla CLA
Modified: 2022-06-09 10:21 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen DiMilla CLA 2011-12-12 12:13:23 EST
Build Identifier: eclipselink-2.3.0.v20110604-r9504

Using entity:

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

    private int	     	     id;
    private String	     firstName;
    private String	     lastName;
    private float	             salary;


    public Employee() {
    }

    public Employee(int id, String firstName, String lastName, float salary)
    {
        	this.id = id;
        	this.firstName = firstName;
        	this.lastName = lastName;
		this.salary = salary;
    }

   // ===========================================================
   // getters and setters for the state fields

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

    @Column(name="FIRSTNAME")
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(name="LASTNAME")
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Column(name="SALARY")
    public float getSalary() {
        return salary;
    }
    public void setSalary(float salary) {
        this.salary = salary;
    }

------------------
client code:

            et.begin();
            System.out.println("Invoking query");
            em.createQuery("UPDATE Employee e SET e.salary = e.salary * 10.0").getLockMode();
            System.out.println("IllegalStateException was not thrown");
            et.commit();
        } catch (IllegalStateException ise) {
            System.out.println("Exception Caught as Expected");
        } catch (Exception e) {
            System.out.println("Unexpected exception occurred", e);
            e.printStackTrace();
        }

------------------
output:
Invoking query
Unexpected exception occurred
java.lang.IllegalArgumentException: A lock type can only be used with a select query (which allows the database to be locked where necessary).
 	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getLockMode(EJBQueryImpl.java:625)

Reproducible: Always
Comment 1 Tom Ware CLA 2012-04-05 11:01:24 EDT
Updating target milestone.
Comment 2 Tom Ware CLA 2013-02-05 08:48:34 EST
I am seeing the IllegalStateException in the current version.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:21:37 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink