Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366464 - EntityManager.getLockMode ( Object ) does not throw TransactionRequiredException when there is no transaction
Summary: EntityManager.getLockMode ( Object ) does not throw TransactionRequiredExcept...
Status: CLOSED 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: Tom Ware CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-12 16:46 EST by Stephen DiMilla CLA
Modified: 2022-06-09 10:07 EDT (History)
3 users (show)

See Also:


Attachments
proposed fix (16.19 KB, patch)
2013-02-05 10:20 EST, Tom Ware 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 16:46:58 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();
            EntityManager em = getEntityManager();

            Query query = em.createQuery(
                    "select e from Employee e where e.id < 10 ");

            query.setLockMode(LockModeType.PESSIMISTIC_READ);
            Collection<Employee> c = query.getResultList();
            et.commit();
            System.out.println("isActive="+getEntityTransaction().isActive());
            int expected = 9;
            int found = 0;
            for (Employee e : c) {
                try {
                    em.getLockMode(e);
                } catch (TransactionRequiredException tre) {
                    found++;
                }
            }
            if (found == expected) {
                System.out.println("Got expected number of TransactionRequiredExceptions"+expected);
            } else {
                System.out.println("Number of TransactionRequiredException Expected:" + c.size() + ", Actual:" + found);
            }

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


isActive=false
Number of TransactionRequiredException Expected:9, Actual:0

Reproducible: Always
Comment 1 Tom Ware CLA 2012-04-05 11:01:17 EDT
Updating target milestone.
Comment 2 Tom Ware CLA 2013-02-05 10:20:11 EST
Created attachment 226574 [details]
proposed fix
Comment 3 Tom Ware CLA 2013-02-05 11:50:13 EST
Bugs 366407, 366427, 366464, 382537 fixed in same transaction

Reviewed by Guy Pelletier

Tests added to JPA 2.1 test suites, QueryTestSuite, EntityManagerTestSuite and EntityManagerFactoryTestSuite

Tested with JPA LRG
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:05:42 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:07:51 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink