cancel
Showing results for 
Search instead for 
Did you mean: 

Explicit locking of Entity JavaBean

Former Member
0 Kudos

Hi!

I am developing local WD application based on EJB model using SAP NetWeaver Developer Studio 7.0.12

There's Employee entity javabean, that is shown as a table on EmployeeView webdynpro view (model node, bound to controller).

There's also EmployeeEdit webdynpro view, where Employee entity javabean is shown as set of InputFields (same model node, bound to controller).

When user clicks Save button in EmployeeEdit view, changed values are saved.

The problem arises when two users want to change the same record of Employee entity. Both can go to EmployeeEdit view, change values of record and click Save button, because actual transaction for saving is implemented only when users click Save button.

The workaround for this would be explicit locking of entity record when first user goes to EmployeeEdit view, if it's not already locked. But I couldn't find enough information about this.

[EJBLocking interface|http://help.sap.com/javadocs/nw04/current/en/com/sap/engine/interfaces/ejb/locking/EJBLocking.html] might be what I need, but I don't know how to use it.

This is how I tried to use EJBLocking:


	public void ejbHomeLockMe() {
		EJBLocking ejbl = null;
		Context ctx = null;
		try {
			ctx = new InitialContext();
			ejbl = (EJBLocking) ctx.lookup("java:comp/EJBLocking");
		} catch (NamingException ne) {
			ne.printStackTrace();
			throw new OklaException(ne.getMessage());
		}
		try {
			DataSource ds = (DataSource) ctx.lookup("jdbc/OKLA_DS");
			ejbl.lock( //here I get NullPointerException
				TableLocking.LIFETIME_TRANSACTION,
				ds.getConnection(),
				(EntityBean) this,
				TableLocking.MODE_EXCLUSIVE_NONCUMULATIVE);
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			throw new OklaException(sqle.getMessage());
		} catch (NamingException ne) {
			ne.printStackTrace();
			throw new OklaException(ne.getMessage());
		}
	}

and here's the exception


   java.lang.NullPointerException
 
    at com.sap.engine.services.ejb.entity.pm.lock.EJBLockingImpl.getPKMap(EJBLockingImpl.java:108)
    at com.sap.engine.services.ejb.entity.pm.lock.EJBLockingImpl.lock(EJBLockingImpl.java:48)
    at my.company.okla.employee.EmployeeBean.ejbHomeLockMe(EmployeeBean.java:92)
...

Can anyone give me an idea about all this?

Thanks in advance

Renat

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I used TableLocking instead and that solved my problem.

I had to pass physical name of table and primary key column name and that's what makes me doubt this decision.

Renat