I have a quite interesting issue. I set some values on the server, send the bean to client and then it comes back to the server without that values.
Here is what I do:
1. Client requests some beans from DB through EntityRequest.getEntity(params)
2. I fetch a bean from database through Hibernate
3. I set some transient property (I need them on client side and don't want them to store in DB)
4. Send the bean through EntityRequest's method to client.
5. Client changes some other values and calls persist.
6. Server receives back his bean and
- is has properly set properties from the client
- the property set from the server (step no. 3) are ERASED / IGNORED.
It looks like RF mechanism would send me freshly DB loaded version with only changes from client. I did some research and it looks like there must have been some bean version issue. The bean has version set (see below) and it is used by Hibernate and I guess by RF also.
What should I do to get my value to client and back? I tried some "entity.version++;" on step 3, but it doesn't work.
@Entity
public class Person {
@Id
@GeneratedValue
private Long id;
@Version
private Integer version;
@Field
private String name;
@Transient
private Long participationId;
...
public Long getId() {
return id;
}
public Integer getVersion() {
return version;
}
...
}
public static Person findPerson(Long id) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
try {
Object p = session.get(Person.class, id);
session.getTransaction().commit();
return p != null ? (Person) p : null;
} catch (RuntimeException e){
logger.error("Person.findPerson", e);
session.getTransaction().rollback();
throw e;
}
}
With the help of Thomas Broyer I understood more the RequestFactory mechanism and this has led me to the solution. RequestFactory on returning the object from client side does not take domaing object out of a cache but rather fetches fresh one and does diff to it. The fetch is done either using Locator or domain objet's find(id) function. In my case was find(id).
The solution is an ugly hack, I know, but it works. This is on my entity
public class Person {
...
@Transient
private Long participationId;
@Transient
private Long participationStoreId;
...
}
Before I sent it to RF I load participationId. On the client side, to keep it, before sending back I do:
person.setParticipationStoreId(person.getParticipationId());
Before you throw eggs at me, I repeat: I know it is an ugly hack. But in some cases I need some value on entity to the client and back and I don't want it in DB. This was the only way that works.