my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes Container Error in FindBy methods in JBoss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Container Error in FindBy methods in JBoss " Watch "Container Error in FindBy methods in JBoss " New topic
Author

Container Error in FindBy methods in JBoss

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Hi
I have an error in an entity bean that i have deployed on JBoss 2.4.4. I have implemented a findByName method in my BMP entity Bean. In the method which takes a non pk string field and checks the database ( successfully ) for entries and creates a Enumeration of primary key classes.
When the client calls this method it gets back an enumeration containing bean types but each of the fields in the bean type are null.
from my debugging code i discivered that, as expected, the PK constructor is called then the beans ejbLoad method is called. Although the id pk field is set in the PrimaryKey class this does not filter through to the bean and consequently the select in load cannot find the entry. This seems to me as if the container is not setting the id field in the bean.
As you can see from my deployment file i have set the PK class.
<entity>
<description>UserImpl</description>
<ejb-name>UserImpl</ejb-name>
<home>com.users.EJB.UserHome</home>
<remote>com.users.EJB.User</remote>
<ejb-class>com.users.EJB.UserImpl</ejb-class>
<reentrant>false</reentrant>
<persistence-type>Bean</persistence-type>
<prim-key-class>com.users.EJB.UserPK</prim-key-class>
<prim-key-field>id</prim-key-field>

<resource-ref>
<description>Datasource for the Database</description>
<res-ref-name>java:/OracleDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

</entity>
Both the pk and the bean class have a field id which is public. The PK class constructor takes an integer in and sets the id with it.
can anybody please offer me any suggestions as to why i cannot get this method to work. any help would be appreciated.
David
seshu kumar
Greenhorn

Joined: Jun 13, 2002
Posts: 23
in ejbLoad and ejbRemove you need to get the Primarykey instance from EntityContext only!
Check if you are trying to use your local class variable holding the primary key instance.
public void ejbLoad()
{
PKClass pk = e_ctx.getPrimaryKey();
}
seshu kumar
Greenhorn

Joined: Jun 13, 2002
Posts: 23
in ejbLoad and ejbRemove you need to get the Primarykey instance from EntityContext only!
Check if you are trying to use your local class variable holding the primary key instance.
public void ejbLoad()
{
PKClass pk = e_ctx.getPrimaryKey();
//Then use the pk to load the
//entity from database
//.......
}
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
cheers seshu. i now have a slight problem with bean locking in my activate method. on this line
id = new Integer( (String)context.getPrimaryKey() ).intValue() ;
i get an exception, see below. i don't know how i could have locked the bean, container transaction probably. i would think it is a depoyment config thing but i am not to sure. has anybody seen this and know how to fix it?
thanks for any help.
[INFO,Default] UserEntityBean::ejbActivate()
[ERROR,UserImpl] TRANSACTION ROLLBACK EXCEPTION:
javax.transaction.TransactionRolledbackException: removing bean lock and it has tx set!; nested exception is:
java.lang.IllegalStateException: removing bean lock and it has tx set!
java.lang.IllegalStateException: removing bean lock and it has tx set!
at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.removeRef(QueuedPessimisticEJBLock.java:441)
at org.jboss.ejb.BeanLockManager.removeLockRef(BeanLockManager.java:78)
at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:142)
at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:138)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:602)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:100)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:170)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:428)
at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:504)
at org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(GenericProxy.java:335)
at org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.invoke(EntityProxy.java:133)
at $Proxy97.getId(Unknown Source)
at com.users.EJB.UserManagerSessionBean.isValidUser(UserManagerSessionBean.java:81)
at java.lang.reflect.Method.invoke(Native Method)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:542)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:82)
[ June 20, 2002: Message edited by: David Raid ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Container Error in FindBy methods in JBoss
 
Similar Threads
Starting WL 5.1 after deploying an Entity bean
javax.ejb.CreateException: Error checking if entity exists
cmp identity_insert
"variable contained illegal space"
web.xml error