Things I lost in the passage from Entity EJB 2.1 to Entity E
gdellelce Sep 22, 2005 7:41 AMThere are 2 things I've lost in the passage from Entity EJB 2.1 to Entity EJB 3.0 so far:
1) EntityContext and in particular getCallerPrincipal
for a reason why I need it you can read this thread:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=67448
2) automatic container management of cmr (container managed relationship) fields (see section 10.4.2.2
of "Enterprise JavaBeans Specification, Version 2.1"
in fact 3.0 spec says in section 3.2.3 of "JSR 220: Enterprise JavaBeans,Version 3.0 Java
Persistence API":
"It is the developer?s responsibility to keep the in-memory references held on the owning side and those held
on the inverse side consistent with each other when they change.
It is particularly important to ensure that changes to the inverse side of a relationship result in
appropriate updates on the owning side, so as to ensure the changes are not lost when they are
synchronized to the database. Developers may choose whether or not to update references
held by the inverse side when the owning side changes, depending on whether the application
can handle out-of-date references on the inverse side until the next database refresh occurs."
For the first point I haven't find a convenient solution yet, while for the second point
I created some convenient wrapper of referent fields which will maintain the relation consistent
so if you have a 1:N relation from class Parent and class Child instead of declaring
Parent parent;
and
Set children;
you declare
RelationPtrN1 parent = new RelationPtr1N(this);
@ManyToOne
@JoinColumn(name = "IDPARENT")
public Parent getParent() { return parent.get(); }
public void setParent(Parent p) { parent.set(p); }
and
RelationPtr1N<Set> children = new RelationPtr1N<Set>(this, new Set<Child());
@OneToMany(mappedBy = "parent", cascade = { CascadeType.ALL })
public Set getChildren() { return children.get(); }
public void setChildren(Set c) { children.set(c); }
public void addChild(Child c) { children.add(c); }
public void removeChild(Child c) { children.remove(c); }
If you are interested I can post the code.
I wonder if there is a best solution than this and for a convenient solution for point 1).
THANK YOU for all hints in advance
Gianfranco