[EJB/JBoss] - Is passivation enabled twice?
by javidjamae
I've yet to verify, but it looks like passivation is enabled twice for stateful session beans in the all configuration of JBoss-5.0.0.Beta3.
1) In server/all/conf/standardjboss.xml, the container for "Standard Stateful SessionBean" has the StatefulSessionFilePersistenceManager persistence manager set.
2) In server/all/deploy/cluster/ejb3-cluster-sfsbcache-beans.xml, there is a cacheLoaderConfig property set to a bean named EJB3SFSBCacheLoaderConfig, which has a passivation property set to true. This enables passivation over JBoss cache.
Is passivation happening twice out of the box, once to the file system and once to the cache? If so, is this an oversight? Should the filesystem based passivation be turned off when running the all configuration?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117236#4117236
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117236
18 years, 3 months
[JBossWS] - Re: Writing a client - no examples for BindingProvider based
by mjhammel
I got a little further now. First, http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html explains the problem a bit - you can't use injection in Web apps, which I assume translates to Web Services. So I used the technique listed in the blog.
This worked, eventually, after I added a couple of lines to my persistence.xml, as suggested by the JBOSS App Server entity config documentation (http://docs.jboss.org/ejb3/app-server/reference/build/reference/en/html/e...).
updated persistence.xml
<persistence>
|
| <persistence-unit name="Crunch">
| <jta-data-source>java:/CrunchDS</jta-data-source>
| <properties>
| <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
| <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
| <property name="hibernate.connection.url" value="jdbc:mysql://localhost/crunch"/>
| <property name="hibernate.connection.username" value="root"/>
| <property name="jboss.entity.manager.jndi.name" value="java:/CrunchPersistence"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/CrunchFactory"/>
| </properties>
| </persistence-unit>
| </persistence>
The two jndi related properties bound the names specified in the property to the application so that they could be referenced an InitialContext.lookup() (see code below).
Now I can see the Session Bean retrieving the data from the database, but then it immediately complains about some "lazy" thing:
17:11:24,689 INFO [STDOUT] Subscriber.find(): em is not null; returning subscriber for guid = CRUNCH-DEFAULT-SUPERUSER
| 17:11:25,015 INFO [STDOUT] Subscriber name : SuperUser
| 17:11:25,015 INFO [STDOUT] Subscriber email: admin@localhost
| 17:11:25,176 ERROR [LazyInitializationException] failed to lazily initialize a collection of role: com.cei.crunch.ejb.Subscriber.crunchroleses, no session or session was closed
It should be noted that "crunchroleses" is a field in a generated class. The class, com.cei.crunch.ejb.Subscriber, is generated by the reverse engineering process provided through Hibernate in order to generate EJB code for an existing database. So maybe there is some (yet more) additional configuration of Hibernate that needs to be done.
My Web Services code now looks like this:
package com.cei.crunch.server.ws.SubscriberServices;
|
| import javax.ejb.*;
| import javax.jws.WebService;
| import javax.jws.WebMethod;
| import javax.jws.soap.SOAPBinding;
| import javax.persistence.*;
| import javax.naming.InitialContext;
|
| import com.cei.crunch.server.util.SubscriberUtil;
| import com.cei.crunch.ejb.Subscriber;
|
| /* Make this an EJB3 service endpoint. */
| @Stateless
| @Remote(SubscriberServices.class)
|
| /* Make this an Web Services endpoint. */
| @WebService(endpointInterface = "com.cei.crunch.server.ws.SubscriberServices.SubscriberServicesEndpoint")
| @SOAPBinding(style = SOAPBinding.Style.RPC)
|
| /**
| * The .Crunch interface to Subscriber Services
| */
| public class SubscriberServices implements SubscriberServicesEndpoint {
|
| @WebMethod
| public Subscriber findSubscriber(String guid)
| {
| Subscriber s;
| SubscriberUtil su = new SubscriberUtil();
|
| s = su.find(guid);
| if ( s == null )
| System.out.println("su.find() returned null.");
| return s;
| }
|
| }
My Session Bean code, which is called by the Web Services code above, looks like this:
package com.cei.crunch.server.util;
|
| import javax.ejb.*;
| import javax.jws.soap.SOAPBinding;
| import javax.persistence.*;
| import javax.naming.InitialContext;
| import javax.transaction.UserTransaction;
| import javax.annotation.Resource;
|
| import com.cei.crunch.ejb.Subscriber;
|
| /* Make this an EJB3 service endpoint. */
| @Stateless
|
| /**
| * The .Crunch interface to Subscriber Services
| */
| public class SubscriberUtil implements SubscriberUtilInterface {
|
| @Resource
| private UserTransaction utx;
|
| public Subscriber find(String guid)
| {
| InitialContext ctx = null;
| EntityManager em = null;
| try {
| ctx = new InitialContext();
| em = (EntityManager) ctx.lookup("java:/CrunchPersistence");
| }
| catch (Exception e)
| {
| // throw new WebServiceException(ex);
| System.out.println("Subscriber.find(): context lookup failure.");
| e.printStackTrace();
| return null;
| }
|
| if ( em == null )
| {
| System.out.println("Subscriber.find(): em is null; can't find subscriber");
| return null;
| }
| else
| {
| Subscriber s = null;
| System.out.println("Subscriber.find(): em is not null; returning subscriber for guid = " + guid);
| try {
| utx = (UserTransaction) ctx.lookup("java:/comp/UserTransaction");
| utx.begin();
| s = em.find(Subscriber.class, guid);
| utx.commit();
| }
| catch (Exception e)
| {
| System.out.println("Subscriber.find(): find problem.");
| e.printStackTrace();
| }
| if ( s != null )
| {
| System.out.println("Subscriber name : " + s.getFirstname());
| System.out.println("Subscriber email: " + s.getEmailAddress());
| }
| return s;
| }
| }
|
| }
You'll note that I manually create a UserTransaction here. This is because if I don't do this, no transaction is injected into the Session Bean by the @Resource (I don't know why). And if I don't create the UserTransaction before referencing the EntityManager (em), I get a null pointer exception when I do reference it.
My best guess at this is that the UserTransaction is in the wrong place - it may need to go in the Web Services class before it calls the Session Bean. However, that's pretty much a WAG at this point.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117235#4117235
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117235
18 years, 3 months
[JBoss Seam] - Does facesMessages.clear() work for conversion errors?
by supernovasoftware.com
Using Seam 2.0 on 4.2.2
I have a converter that I use for a datatable with dropdown filters and a button to update multiple values at once.
Each row has a single input box that should only accept positive doubles. When a dropdown changes I use a4j:support to rerender the entire datatable.
The update button also rerenders the datatable.
If I
throw new ConverterException(new FacesMessage("You must enter a positive number."));
The table is reloaded and the FacesMessages are correctly attached to the correct input components, but all values are reverted to their initial value and any changes are lost even if that field passes conversion.
If I
throw new ConverterException("You must enter a positive number.");
and then I change the filter and reload the datatable, both the value and the error message are carried with that row. The rest of the columns contain the correct data. I have to select a filter that has no results or less rows than where the conversion error occurs to clear it. Also the error message is not reflected and the error reads "value could not be converted to the expected type."
facesMessages.clear();
seemed to work when I was adding them in a validator
private void addMessage(UIComponent component, Object value)
| {
| HtmlInputText htmlInputText = (HtmlInputText) component;
| htmlInputText.setValid(false);
| facesMessages.addToControl(htmlInputText.getId(), new FacesMessage("Must be >= 0."));
| }
, but not when the converter adds them.
1. How can I clear the conversion errors when I change the filter?
2. Or, how can I throw the error with the FacesMessage and have the values perserverd?
Complete converter code
| @Name("positiveDoubleConverter")
| @BypassInterceptors
| @Converter
| public class PositiveDoubleConverter implements javax.faces.convert.Converter
| {
| public PositiveDoubleConverter() { }
|
| public String getAsString(FacesContext context, UIComponent component, Object value)
| {
| return (value==null) ? null : value.toString();
| }
|
| public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException
| {
| if(value==null || value.length()<1) return null;
| try {
| Double d = Double.parseDouble(value);
| if(d<0)
| {
| throwConverterException();
| }
| return d;
| } catch (NumberFormatException e) {
| return throwConverterException();
| }
| }
|
| private Object throwConverterException() throws ConverterException
| {
| //throw new ConverterException(new FacesMessage("You must enter a positive number."));
| throw new ConverterException("You must enter a positive number.");
| }
|
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117233#4117233
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117233
18 years, 3 months
[JBoss Portal] - Caching of navigation path
by tulumvinh
Hello all,
Question: How do I disable the caching of navigation in a portlet?
Scenario: Login to portal as user "admin" -> click on 'admin" link -> clickon the "home" tab -> navigate to the detail pages of a portal. Then click on the "members" tab, when you click on the "home" tab, you are automatically at the detail page. It seems that there is caching done on the navigation path within the portlet.
Questions:
- This navigation path caching does not seem to be done with Transient/Session or persistent cookies, true?
- is this caching control by <expiration-cache> tag within portlet.xml? I set the tag to a value of 0 but it didn't work.
- How do I inactivate this caching.
I am using:
JBoss AS 4.2.1 and JBoss Portal 2.6.2
Any guidance is appreciated.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117229#4117229
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117229
18 years, 3 months