Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
The only usecase for the ejbActivate/ejbPassivate callbacks is to cleanup resources like jms connections. The logic for calculating the derived value you showed is what needs to be done, and is a cache mechanism as ejbLoad is only called when the cache state is inconsistent with the persistent store basis you entity bean configuration. By definition, when the entity is passivated the cached state is gone and must be either reloaded from a persistent store or recomputed. If you don't want these entities passivated change the cache policy. From the ejb 2.0 spec: 10.3.9 Non-persistent state The Bean Provider may use instance variables in the entity bean instance to maintain non-persistent state, e.g., a JMS connection. The Bean Provider can use instance variables to store values that depend on the persistent state of the entity bean instance, although this use is not encouraged. The Bean Provider should use the ejbLoad() method to resynchronize the values of any instance variables that depend on the entity bean’s persistent state. In general, any non-persistent state that depends on the persistent state of an entity bean should be recomputed during the ejbLoad() method. -- Scott Stark Chief Technology Officer JBoss Group, LLC Pedro Salazar wrote: Technical I can, but I won't be able to implement a cache mechanism with the any flag. I mean, I won't be able to know if data is really changed and I must process all data again, or if the cache should persist. Because the load() should happen always after a activate(), with changes or without them. BTW, can the scenario below happen ( it happened to me ): - I process some data (business method) and cache some data for the entity #1. - I let the entity bean go to passivate state. - I test the cache for the entity #2 and for the entity #1. The cache exist for the entity #2 but doesn't exist for entity #1. Both entity beans went to the pool, but when I invoked them again, the pool gave the objects swapped for the entity beans. So, if the cache is not possible to do in the entity beans, what is the need of the activate() if the load() will always occur? And, we cannot access to any of the entity beans methods there... regards, Pedro Salazar. --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
> > I've read the EJB spec but I only found one error that happens when the > > load is called on my entity bean. The load is always called before an > > activate() even the entity bean isn't changed (read-only for instance), > > which would always eliminates my cache effect. > > Are you sure ejbLoad is called before ejbActivate in the same > transaction for the same instance? It should not happen. How could I > reproduce it? > My mistake. Is called *after* the activate and *not before*. Sorry. > > > > So look at my sample below. First, the cache is false, and after the > > first business method is called the cache is set. The cache will be > > unset only when the load() is called that will be when the activate is > > called. > > > > I could remove the unset code in the load() but if my entity bean change > > (e.g. a store procedure) I won't be able to reload my entity bean data > > ever. > > Why? What do you mean? > Technical I can, but I won't be able to implement a cache mechanism with the any flag. I mean, I won't be able to know if data is really changed and I must process all data again, or if the cache should persist. Because the load() should happen always after a activate(), with changes or without them. BTW, can the scenario below happen ( it happened to me ): - I process some data (business method) and cache some data for the entity #1. - I let the entity bean go to passivate state. - I test the cache for the entity #2 and for the entity #1. The cache exist for the entity #2 but doesn't exist for entity #1. Both entity beans went to the pool, but when I invoked them again, the pool gave the objects swapped for the entity beans. So, if the cache is not possible to do in the entity beans, what is the need of the activate() if the load() will always occur? And, we cannot access to any of the entity beans methods there... regards, Pedro Salazar. -- -PS --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
Pedro Salazar wrote: On Fri, 2003-11-21 at 21:13, Alexey Loubyansky wrote: You are doing it wrong. In ejbPassivate the flag should be set to false. Please, read about activation/passivation in the spec. There is also a nice picture on this subject. Alexey, I've read the EJB spec but I only found one error that happens when the load is called on my entity bean. The load is always called before an activate() even the entity bean isn't changed (read-only for instance), which would always eliminates my cache effect. Are you sure ejbLoad is called before ejbActivate in the same transaction for the same instance? It should not happen. How could I reproduce it? So look at my sample below. First, the cache is false, and after the first business method is called the cache is set. The cache will be unset only when the load() is called that will be when the activate is called. I could remove the unset code in the load() but if my entity bean change (e.g. a store procedure) I won't be able to reload my entity bean data ever. Why? What do you mean? Do you have any idea how to improve the cache effect here? " private boolean cache; private String value; public String getValue() { if(cache){ this.logger.info("cached sum is "+this.value); } else { this.logger.info("processing sum..."); int sum=0; for(int i=0;i<1;i++) sum+=i; this.value=String.valueOf(sum); this.logger.info("sum is "+this.value); this.cache=true; } return this.value; } public void ejbLoad() { if(logger.isDebugEnabled()) logger.debug("Load Primitive ..."); this.cache=false; this.value=null; } " regards, Pedro Salazar. --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
On Fri, 2003-11-21 at 21:13, Alexey Loubyansky wrote: > You are doing it wrong. In ejbPassivate the flag should be set to false. > Please, read about activation/passivation in the spec. > There is also a nice picture on this subject. > Alexey, I've read the EJB spec but I only found one error that happens when the load is called on my entity bean. The load is always called before an activate() even the entity bean isn't changed (read-only for instance), which would always eliminates my cache effect. So look at my sample below. First, the cache is false, and after the first business method is called the cache is set. The cache will be unset only when the load() is called that will be when the activate is called. I could remove the unset code in the load() but if my entity bean change (e.g. a store procedure) I won't be able to reload my entity bean data ever. Do you have any idea how to improve the cache effect here? " private boolean cache; private String value; public String getValue() { if(cache){ this.logger.info("cached sum is "+this.value); } else { this.logger.info("processing sum..."); int sum=0; for(int i=0;i<1;i++) sum+=i; this.value=String.valueOf(sum); this.logger.info("sum is "+this.value); this.cache=true; } return this.value; } public void ejbLoad() { if(logger.isDebugEnabled()) logger.debug("Load Primitive ..."); this.cache=false; this.value=null; } " regards, Pedro Salazar. -- -PS --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
RE: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
JBuilder 7 was not able to create valid deployment descriptors in porting from Weblogic to Borland Application Server. Verified issue with Borland support and they were unable to resolve. The lack of support for JBoss was the straw that forced us to investigate alternatives and we now use XDoclet with Eclipse and Ant. Very happy with those choices. They are free but cost was not even on our list of criteria. -Original Message- From: Sasidharan, Manoj [mailto:[EMAIL PROTECTED] Sent: Fri 11/21/2003 5:07 PM To: [EMAIL PROTECTED] Cc: Subject: RE: [JBoss-user] EJB home methods are not allowed to access CMP or CMR Hello All, We are getting this error when our application was ported from Weblogic to JBoss. Does this show a violation of J2EE specs?? FYI, all our CMP/CMR relationships are generated using JBuilder 7 and JBoss Plug-in. Sorry. I thought it was a bug on the server. Please confirm. rgds MS --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user <>
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
You are doing it wrong. In ejbPassivate the flag should be set to false. Please, read about activation/passivation in the spec. There is also a nice picture on this subject. Pedro Salazar wrote: One more thing, when the bean is passivated only the non-transient variables are saved (probably to disk)? Is it about entity beans? Entity beans are returned to the pool after the passivation. Nothing is stored to the disc. What?!? How is that possible? Let me explain: I defined a instance variable (my flag) which I set only when I process a business method which by its turn sets the result value on another instance variable. After the passivation of my bean, I execute again my business method which verifies first the flag to see if the variable has already the computation! And it works!! I mean, I verified by output message that the variable was set, the result was also there. So, the only chance I can see here is that the instance variables must be saved in some place(disk, ...?). What is the pool for entity beans? regards, Pedro Salazar. --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
> > One more thing, when the bean is passivated only the non-transient > > variables are saved (probably to disk)? > > Is it about entity beans? Entity beans are returned to the pool after > the passivation. Nothing is stored to the disc. > What?!? How is that possible? Let me explain: I defined a instance variable (my flag) which I set only when I process a business method which by its turn sets the result value on another instance variable. After the passivation of my bean, I execute again my business method which verifies first the flag to see if the variable has already the computation! And it works!! I mean, I verified by output message that the variable was set, the result was also there. So, the only chance I can see here is that the instance variables must be saved in some place(disk, ...?). What is the pool for entity beans? regards, Pedro Salazar. -- -PS --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
Pedro Salazar wrote: Yes, the bean is read-only, however I set a read timeout of 300ms. It's too low but I don't know if this works in read-only beans, does it? Yes, sure. The default value is -1, which means never timeout. And if true, when the time starts for the timeout? When the container marks the field as clean. For example, when the field is loaded or at synchronization time when the field was updated. Is the passivate an action of timeout? No, at least not that timeout from jbosscmp-jdbc.xml. An instance is passivated when it is removed from the cache and going to be put back to the pool. Check the spec on when an instance is passivated and cache-policy configuration in jboss.xml. One more thing, when the bean is passivated only the non-transient variables are saved (probably to disk)? Is it about entity beans? Entity beans are returned to the pool after the passivation. Nothing is stored to the disc. thanks. regards, Pedro Salazar. --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
On Fri, 2003-11-21 at 13:48, Alexey Loubyansky wrote: > Is bean read-only in jbosscmp-jdbc.xml? It should be. > The second thing to keep in mind is that the cache also has some > limitations and, probably, can't keep the whole database in memory. > Yes, the bean is read-only, however I set a read timeout of 300ms. It's too low but I don't know if this works in read-only beans, does it? And if true, when the time starts for the timeout? Is the passivate an action of timeout? One more thing, when the bean is passivated only the non-transient variables are saved (probably to disk)? thanks. regards, Pedro Salazar. -- -PS --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
Is bean read-only in jbosscmp-jdbc.xml? It should be. The second thing to keep in mind is that the cache also has some limitations and, probably, can't keep the whole database in memory. Pedro Salazar wrote: On Thu, 2003-11-20 at 20:02, Alexey Loubyansky wrote: Can't you calculate the value once and add a flag 'calculated' that will indicate it? Good hint! But, I tried but I didn't understand one thing! I invoke my a stateless method that calculates the sum of i from 1 to 1, and put it in cache. However, after my bean has passivated, I invoked again my method to verify if the cache value has persisted, and realized a few things: 1- The cache has persisted (OK as expected) 2- After the primitive has been activated, the bean was LOADED??? I didn't understood why is that happened? My entity bean is read-only!!! Every time the bean is activated is also loaded from the database??? I read the spec and the sequential diagrams confirmed that but I thought if a entity bean was read-only, the passivate wouldn't serialize the values avoiding the loading from database...? There is a log below showing this case: " 21 Nov 2003 11:45:15,355 DEBUG [pt.ptinovacao.nginpro.uif.service.ejb.PrimitiveBean] Passivate Primitive 21 Nov 2003 11:45:32,698 DEBUG [pt.ptinovacao.nginpro.uif.service.ejb.PrimitiveBean] Activate Primitive 21 Nov 2003 11:45:32,702 DEBUG [pt.ptinovacao.nginpro.uif.service.ejb.PrimitiveBean] Load Primitive ... 21 Nov 2003 11:45:32,704 INFO [pt.ptinovacao.nginpro.uif.service.ejb.PrimitiveBean] (cache) sum is 49995000 21 Nov 2003 11:45:32,705 INFO [pt.ptinovacao.nginpro.uif.service.ejb.ServiceInfoBean] value->49995000 " regards, Pedro Salazar. --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
On Thu, 2003-11-20 at 20:02, Alexey Loubyansky wrote: > Can't you calculate the value once and add a flag 'calculated' that will > indicate it? > Good hint! But, I tried but I didn't understand one thing! I invoke my a stateless method that calculates the sum of i from 1 to 1, and put it in cache. However, after my bean has passivated, I invoked again my method to verify if the cache value has persisted, and realized a few things: 1- The cache has persisted (OK as expected) 2- After the primitive has been activated, the bean was LOADED??? I didn't understood why is that happened? My entity bean is read-only!!! Every time the bean is activated is also loaded from the database??? I read the spec and the sequential diagrams confirmed that but I thought if a entity bean was read-only, the passivate wouldn't serialize the values avoiding the loading from database...? There is a log below showing this case: " 21 Nov 2003 11:45:15,355 DEBUG [pt.ptinovacao.nginpro.uif.service.ejb.PrimitiveBean] Passivate Primitive 21 Nov 2003 11:45:32,698 DEBUG [pt.ptinovacao.nginpro.uif.service.ejb.PrimitiveBean] Activate Primitive 21 Nov 2003 11:45:32,702 DEBUG [pt.ptinovacao.nginpro.uif.service.ejb.PrimitiveBean] Load Primitive ... 21 Nov 2003 11:45:32,704 INFO [pt.ptinovacao.nginpro.uif.service.ejb.PrimitiveBean] (cache) sum is 49995000 21 Nov 2003 11:45:32,705 INFO [pt.ptinovacao.nginpro.uif.service.ejb.ServiceInfoBean] value->49995000 " regards, Pedro Salazar. -- -PS --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
Can't you calculate the value once and add a flag 'calculated' that will indicate it? Pedro Salazar wrote: Greetings, I would like to get access to some information available on my entity bean during the activate() method to prepare it and avoid doing it every call to in a interface method. However, I'm getting an error that says I cannot access that information. " 2003-11-20 19:17:01,378 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException in method: public abstract java.lang.String pt.ptinovacao.nginpro.uif.service.ejb.interfaces.PrimitiveLocal.getName(), causedBy: java.rmi.NoSuchObjectException: EJB home methods are not allowed to access CMP or CMR fields: methodName=getPTypeId [snip] " But if I can't do that how should I prepare information from my entity bean to avoid repeating processing always the same operations in my entity beans? for instance, imagine I have a 2 or more numbers fields in my entity beans, and I would like to provide a method that returns the sum of all numbers. Every time I call a interface method, I must do the sum operation. But, if I could do it in the activate method (since my entity bean is read-only), I could gain some performance. Is there any work around to solve my problem? thanks. regards, Pedro Salazar. --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] EJB home methods are not allowed to access CMP or CMR
Unfortunately, it is a spec violation. 10.5.2 Bean Provider’s entity bean instance’s view public void ejbActivate(); The container invokes this method on the instance when the container picks the instance from the pool and assigns it to a specific entity object identity. The ejbActivate() method gives the entity bean instance the chance to acquire additional resources that it needs while it is in the ready state. This method executes with an unspecified transaction context. The entity bean must not attempt to access its persistent state or relationships using the accessor methods during this method. The instance can obtain the identity of the entity object via the getPrimaryKey(), getEJBLocalObject(), or getEJBObject() method on the entity context. The instance can rely on the fact that the primary key and entity object identity will remain associated with the instance until the completion of ejbPassivate() or ejbRemove(). Pedro Salazar wrote: Greetings, I would like to get access to some information available on my entity bean during the activate() method to prepare it and avoid doing it every call to in a interface method. However, I'm getting an error that says I cannot access that information. " 2003-11-20 19:17:01,378 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException in method: public abstract java.lang.String pt.ptinovacao.nginpro.uif.service.ejb.interfaces.PrimitiveLocal.getName(), causedBy: java.rmi.NoSuchObjectException: EJB home methods are not allowed to access CMP or CMR fields: methodName=getPTypeId [snip] " But if I can't do that how should I prepare information from my entity bean to avoid repeating processing always the same operations in my entity beans? for instance, imagine I have a 2 or more numbers fields in my entity beans, and I would like to provide a method that returns the sum of all numbers. Every time I call a interface method, I must do the sum operation. But, if I could do it in the activate method (since my entity bean is read-only), I could gain some performance. Is there any work around to solve my problem? thanks. regards, Pedro Salazar. --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] EJB home methods are not allowed to access CMP or CMR
Greetings, I would like to get access to some information available on my entity bean during the activate() method to prepare it and avoid doing it every call to in a interface method. However, I'm getting an error that says I cannot access that information. " 2003-11-20 19:17:01,378 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException in method: public abstract java.lang.String pt.ptinovacao.nginpro.uif.service.ejb.interfaces.PrimitiveLocal.getName(), causedBy: java.rmi.NoSuchObjectException: EJB home methods are not allowed to access CMP or CMR fields: methodName=getPTypeId [snip] " But if I can't do that how should I prepare information from my entity bean to avoid repeating processing always the same operations in my entity beans? for instance, imagine I have a 2 or more numbers fields in my entity beans, and I would like to provide a method that returns the sum of all numbers. Every time I call a interface method, I must do the sum operation. But, if I could do it in the activate method (since my entity bean is read-only), I could gain some performance. Is there any work around to solve my problem? thanks. regards, Pedro Salazar. -- -PS --- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user