[jboss-user] [JBossWS] - Re: avoid lazy-initialization exceptions
mazz@jboss.com
do-not-reply at jboss.com
Thu Oct 25 09:09:57 EDT 2007
The SLSB and entity is very simple. I've included the relevant SLSB interface definition and entity code below. The specific issue here is our login() method returns a Subject - and the Subject, although it has a Role relationship, we do not eagerly load it. The caller to login() never needs to know the role relationship data, and because of that, we increase performance by never asking the persistence layer to load that data before returning the Subject. While this is a very specific example, this design paradigm is all through our code. In fact, I have to believe this is a general problem everyone will have (since this is a big reason behind using LAZY vs. EAGER loading).
Not sure how to annotate the entity, because would that mean we can either ALWAYS or NEVER the data? But we know will we need it sometimes, but not always (i.e. sometimes a caller will call a different method that returns a Subject and that Subject WILL have the role information loaded and we thus WILL want that data go through the JAXB engine and returned to the web client).
I think we need some way to customize the way JAXB processes the returned entity or we need some annotation on a per-SLSB method. We are looking at @XMLJavaTypeAdapter as a possible way to do something, but we aren't sure yet until we try it out.
@WebService
| @SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
| public interface SubjectManagerRemote {
| @WebMethod
| Subject login(String user, String password);
@Entity
| @Table(name = "ON_SUBJECT")
| public class Subject implements Externalizable {
| ...
| @ManyToMany
| @JoinTable(name="ON_SUBJECT_ROLE_MAP",
| joinColumns={@JoinColumn(name="SUBJECT_ID")},
| inverseJoinColumns={@JoinColumn(name="ROLE_ID")})
| private java.util.Set<Role> roles;
| ...
| public java.util.Set<Role> getRoles() {
| return this.roles;
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4098807#4098807
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4098807
More information about the jboss-user
mailing list