[EJB 3.0] - Predestroy!
by hceylan
Hello,
I have been thinking about starting a topic on "When should the PreDestroy callback called?" for some time.
I have been developing EJBs over two years and also as I closely observed the evolution of the EJB3 code base in Jboss at the source level. Not to mention EJB3 spec pdf is on my desktop ;-)
I have some local resources in one of my projects that must be definitely released on EJBs' destroy.
Looking at SimpleStatefulCache, I see that a in 5 minutes (by default) SFSB is passivated and it stays "forever" on the disk.
Spec is not clear enough about from then on what to do. It does state that after some extended time, the container should remove the handles, references etc., and annotates the PreDestroy callbacks next to the remove driven and timeout driven transitions to "does not exist" state. However in further explanation in the text, clearly says that preDestroy is called on remove method invocation but ignores the issue in timeout driven cases. (Ref Spec, P76, pragraph starts as "While the instance is in the passivated state, the...")
So Jboss EJB implementation is correct in that way. However, I strongly think the spec is unclear in this scenario. Resources allocated in PostConstruct, init and throughout the beans usage, MUST be released. Therefore preDestroy must be guaranteed to be called.
This might even be extended to undeployment of the container.
Therefore, I would like to ask the opinions of the people whether I am right on:
- A second pool of passivated beans required.
- After some designated time passivated beans must be destroy forever.
- Before the point above preDestroy method(s) must be called.
Regards,
Hasan ceylan
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4015695#4015695
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4015695
19Â years, 2Â months
[EJB 3.0] - failed to lazily initialize a collection of role: mall.entit
by jojof
hi
I have two entity Beans
@Entity
@Table(name = "items")
public class Item implements Serializable {
...
@ManyToOne
@JoinColumn(name = "CATEGORY_ID")
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
}
-------------------------
@Entity
@Table(name = "categories")
public class Category implements Serializable {
private Collection items;
...
@OneToMany(mappedBy="category",cascade=CascadeType.ALL)
public Collection getItems() {
return items;
}
public void setItems(Collection items) {
this.items = items;
}
}
-----------------------------------------
in ItemAdminBean.java
@Stateless
public class ItemAdminBean implements ItemAdminInterface {
@PersistenceContext
protected EntityManager em;
...
public Collection getItemsbyCategory(String catName) {
Category category = (Category) em.createQuery("from Category c WHERE c.name LIKE :catName").setParameter("catName",
catName).getSingleResult();
return category.getItems();
}
}
when i call getItemsbyCategory in jsp page i have a problem
<% Collection items = itemAdmin.getItemsbyCategory(request.getParameter("categoryChoice"));
%>
<%for (Iterator iter = items.iterator(); iter.hasNext();) {
Item item = (Item) iter.next();
%>
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: mall.entityDto.Category.items, no session or session was closed
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:246)
org.apache.jsp.online_005fmall.Products_jsp._jspService(Products_jsp.java:111)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
can you help me?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4015686#4015686
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4015686
19Â years, 2Â months