-
1. Re: Attempt to get lock ref with a null object
sesques Apr 21, 2004 9:24 AM (in response to vamsi27e1508)Post your ejb-jar.xml and jbosscmp-jdbc.xml
-
2. Re: Attempt to get lock ref with a null object
vamsi27e1508 Apr 22, 2004 1:19 AM (in response to vamsi27e1508)Hi sesques Thanks for ur interest on me.
Here i am posting
I have created a simple cmp , with 3 fields empId, empFirstname,empLastName.
Here empId is primary key with autoincrement.
When i enter Emp first name, last name using the create method my cmp is working fine and i am able to create new row with autoincrement.
When i call setEmpFirstName() or serEmpLastName() methods from my client geeting an error given below
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
[java] java.rmi.ServerException: RuntimeException; nested exception is:
[java] java.lang.IllegalArgumentException: Attempt to get lock ref with a null object
[java] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
[java] at sun.rmi.transport.Transport$1.run(Transport.java:148)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
[java] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
[java] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
[java] at java.lang.Thread.run(Thread.java:534)
.....21
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar >
[CDATA[No Description.]]
<display-name>Generated by XDoclet</display-name>
<enterprise-beans>
<ejb-name>Employee</ejb-name>
com.emp.empdata.EmployeeHome
com.emp.empdata.Employee
<local-home>com.emp.empdata.EmployeeLocalHome</local-home>
com.emp.empdata.EmployeeLocal
<ejb-class>com.emp.empdata.EmployeeCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>mytestSchema</abstract-schema-name>
<cmp-field >
<field-name>id</field-name>
</cmp-field>
<cmp-field >
<field-name>empFirstName</field-name>
</cmp-field>
<cmp-field >
<field-name>empLastName</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<security-identity><use-caller-identity/></security-identity>
</enterprise-beans>
<assembly-descriptor >
<security-role>
<role-name>every onene</role-name>
</security-role>
<method-permission>
<role-name>every one</role-name>
<ejb-name>Employee</ejb-name>
<method-name>*</method-name>
</method-permission>
<container-transaction>
<ejb-name>Employee</ejb-name>
<method-name>*</method-name>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
jbosscmp-jdbc.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC
"-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"
"http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
<jbosscmp-jdbc>
java:/MySqlDS
<datasource-mapping>mySQL</datasource-mapping>
<create-table>true</create-table>
<remove-table>true</remove-table>
<enterprise-beans>
<ejb-name>Employee</ejb-name>
<cmp-field>
<field-name>id</field-name>
<column-name>emp_id</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<auto-increment></auto-increment>
</cmp-field>
<cmp-field>
<field-name>empFirstName</field-name>
<column-name>emp_firstname</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(25)</sql-type>
</cmp-field>
<cmp-field>
<field-name>empLastName</field-name>
<column-name>emp_lastname</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(25)</sql-type>
</cmp-field>
</enterprise-beans>
</jbosscmp-jdbc>
please let me know the reason.
vamsi -
3. Re: Attempt to get lock ref with a null object
sesques Apr 22, 2004 3:30 AM (in response to vamsi27e1508)You must use the unknow-pk feature to handle auto generated keys
In ejb-jar.xml:
1) declare the primary key class of type java.lang.Object
2 ) declare the return type of ejbCreate of java.lang.Object
in jbosscmp-jdbc.xml :
3 ) declare the unknow-pk and add an entity command as follows in :<unknown-pk> <unknown-pk-class>java.lang.Integer</unknown-pk-class> <field-name>id</field-name> <column-name>emp_id</column-name> <jdbc-type>INTEGER</jdbc-type> <sql-type>INTEGER</sql-type> <auto-increment/> </unknown-pk> <entity-command name="mysql-get-generated-keys">
I hope this helps you -
4. Re: Attempt to get lock ref with a null object
vamsi27e1508 Apr 22, 2004 5:41 AM (in response to vamsi27e1508)HI sesques
As per your suggestions
1) I declared the primary key class of type java.lang.Object
2 ) I declared the return type of ejbCreate of java.lang.Object given bellow
public java.lang.Object ejbCreate( java.lang.String empFirstName ) throws javax.ejb.CreateException {
//setId(id);
this. setEmpFirstName(empFirstName);
// setEmpLastName(empLastName);
return null;
}
3 declared the unknow-pk and added an entity command
(I added these changes simply at the bottom of jbosscmp-jdbc.xml , with out removing the existing cmp-field declarations for emp_ id
<cmp-field>
<field-name>id</field-name>
<column-name>emp_id</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<auto-increment></auto-increment></cmp-field>
)
After these changes , i tried to deploy but deployment was unsuccessful and i got following error
waring:The type of the primkey-field must match the primary key class.
Then i made primary key class of type java.lang.Integer
After this change deployment was successful, but when i run my
client I got bellow error
(client code
package com.emp.clients;
import com.emp.empdata.*;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import java.rmi.RemoteException;
import java.util.*;
import java.text.*;
public class Client_emp
{
public static void main(String [] args)
{
try
{
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("EmployeeBean");
EmployeeHome home = (EmployeeHome)
PortableRemoteObject.narrow(ref,EmployeeHome.class);
// Employee emp_1 = home.create("Ramu","Vurumi"); // before changes working fine
Employee emp_1 = home.create("Ramu"); // before changes when i call set method
// getting error
emp_1.setEmpLastName(new String("vurumi")); // Attemt to get lock ref with a null
//object
}
catch (java.rmi.RemoteException re){re.printStackTrace();}
catch (javax.naming.NamingException ne){ne.printStackTrace();}
catch (javax.ejb.CreateException ce){ce.printStackTrace();}
// catch (javax.ejb.FinderException fe){fe.printStackTrace();}
// catch (javax.ejb.RemoveException de){de.printStackTrace();}
}
public static Context getInitialContext()
throws javax.naming.NamingException
{
return new InitialContext();
/**** context initialized by jndi.properties file
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
p.put(Context.PROVIDER_URL, "localhost:1099");
return new javax.naming.InitialContext(p);
*/
}
}
)
[java] javax.ejb.CreateException: Could not create entity:java.lang.ClassNotFoundException: com.mysql.jdbc.PreparedStatement
[java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractVendorCreateCommand.insertEntity(JDBCAbstractVendorCreateCommand.java:136)
[java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractVendorCreateCommand.execute(JDBCAbstractVendorCreateCommand.java:76)
[java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:569)
[java] at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:225)
[java] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:270)
[java] at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:725)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:998)
[java] at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
[java] at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:188)
[java] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
[java] at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
[java] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:91)
[java] at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:61)
[java] at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:28)
[java] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
[java] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
[java] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:74)
[java] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:92)
[java] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
[java] at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
[java] at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:477)
[java] at org.jboss.ejb.Container.invoke(Container.java:694)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
[java] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
[java] at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
[java] at sun.reflect.GeneratedMethodAccessor68.invoke(Unknown Source)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
[java] at sun.rmi.transport.Transport$1.run(Transport.java:148)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
[java] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
[java] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
[java] at java.lang.Thread.run(Thread.java:534)
[java] at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
[java] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
[java] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
[java] at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
[java] at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
[java] at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:87)
[java] at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
[java] at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
[java] at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:173)
[java] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
[java] at $Proxy0.create(Unknown Source)
[java] at com.emp.clients.Client_emp.main(Client_emp.java:22)
Please help me
vamsi -
5. Re: Attempt to get lock ref with a null object
sesques Apr 22, 2004 6:31 AM (in response to vamsi27e1508)Keep the java.lang.Object type for primary kay class, but remove the
<primkey-field>id</primkey-field> declaration.
As the primary key is declared as unknown, you cannot set a CMP field as primary key.
Normally, when doing that, no CMP field should be declared for the primary key. But you can anyway, but do not declare the CMP field as primary key.
To find your bean, you must use also the findByPrimaryKey method.
You can have a look to the:
http://www.jboss.org/index.html?module=bb&op=viewtopic&t=47787
topic, which talks about the subject -
6. Re: Attempt to get lock ref with a null object
vamsi27e1508 Apr 23, 2004 2:32 AM (in response to vamsi27e1508)Hi sesques, thanks for replying twise,
in ejb-jar.xml
I removed the cmp field declarion for id, <primkey-field>id</primkey-field> declaration
and i made primary kay class of type ava.lang.Object
<enterprise-beans>
[CDATA[]]
<ejb-name>Employee</ejb-name>
com.emp.empdata.EmployeeHome
com.emp.empdata.Employee
<ejb-class>com.emp.empdata.EmployeeCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Object</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>mytestSchema</abstract-schema-name>
<!-- <cmp-field >
<![CDATA[Returns the id]]>
<field-name>id</field-name>
</cmp-field> -->
<cmp-field >
[CDATA[Returns the empFirstName]]
<field-name>empFirstName</field-name>
</cmp-field>
<cmp-field >
[CDATA[Returns the empLastName]]
<field-name>empLastName</field-name>
</cmp-field>
<security-identity><use-caller-identity/></security-identity>
</enterprise-beans>
In jboss-cmp-jdbc i made few changes
I removed cmp declaration for the field name id
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jbosscmp-jdbc PUBLIC
"-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"
"http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
<jbosscmp-jdbc>
java:/MySqlDS
<datasource-mapping>mySQL</datasource-mapping>
<create-table>true</create-table>
<remove-table>true</remove-table>
<enterprise-beans>
<ejb-name>Employee</ejb-name>
<!-- <cmp-field>
<field-name>id</field-name>
<column-name>emp_id</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<auto-increment></auto-increment>
</cmp-field> -->
<cmp-field>
<field-name>empFirstName</field-name>
<column-name>emp_firstname</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(25)</sql-type>
</cmp-field>
<cmp-field>
<field-name>empLastName</field-name>
<column-name>emp_lastname</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(25)</sql-type>
</cmp-field>
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<field-name>id</field-name>
<column-name>emp_id</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
<auto-increment/>
</unknown-pk>
<entity-command name="mysql-get-generated-keys">
</entity-command>
</enterprise-beans>
</jbosscmp-jdbc>
After these changes i deployed successfully,but when i run
my client i got below error
my client code
EmployeeHome home = (EmployeeHome)
PortableRemoteObject.narrow(ref,EmployeeHome.class);
Employee emp_1 = home.create("Ramu","Vurumi");
run.client_empdata:
[java] javax.ejb.CreateException: Could not create entity:java.lang.ClassNotFoundException: com.mysql.jdbc.PreparedStatement
[java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractVendorCreateCommand.insertEntity(JDBCAbstractVendorCreateCommand.java:136)
[java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractVendorCreateCommand.execute(JDBCAbstractVendorCreateCommand.java:76)
[java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:569)
[java] at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:225)
[java] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:270)
[java] at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:725)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:998)
[java] at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
[java] at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:188)
[java] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
[java] at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
[java] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:91)
[java] at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:61)
[java] at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:28)
[java] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
[java] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
[java] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:74)
Please tell me the problem whether should i include any jar.
Once again Thanks for your great cooperation.. -
7. Re: Attempt to get lock ref with a null object
sesques Apr 23, 2004 3:14 AM (in response to vamsi27e1508)You have
<create-table>true</create-table>
I don't use this feature myself. After deployment, is the table created in the database ? and the emp_id column set to auto-increment ?
If not, the container must generate the key and you must use an entity command name of pk-sql or key-generator. Look at standardjbosscmp-jdbc.xml in the conf directory -
8. Re: Attempt to get lock ref with a null object
vamsi27e1508 Apr 25, 2004 11:44 PM (in response to vamsi27e1508)HI sesques
Using <create-table>true</create-table> feature ,container created table for me with emp_id auto-incremented.
I have changed <entity-command name ="default"> to name="mysql-get-generated-keys"> in the standardjbosscmp-jdbx.xml
After deployment ,when i run my client i still got below error
] java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
[java] java.rmi.ServerError: Unexpected Error; nested exception is:
[java] java.lang.AbstractMethodError: org.gjt.mm.mysql.jdbc2.Connection.prepareStatement(Ljava/lang/String;I)Ljava/sql/PreparedStatement;
[java] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
I have solved my problem using <auto-increment/>, not going for <unknown-pk>
I do not know whether i am correct or not .
Thanks for ur great help , regarding this topic i got some subject from ypu. -
9. Re: Attempt to get lock ref with a null object
sesques Apr 26, 2004 4:58 AM (in response to vamsi27e1508)I ask myself many questions about unknow-pk tag. My application was running on Weblogic before, and I had a hell of a time with database auto-incremented keys (I use MS SQL2000 adn ORACLE and I cannot tell JBoss to create the databases because the databases are existing and quite voluminous).
This tag (unknow-pk) solve my problem, but it seems it is not the case for other people is this forum, especially with MySQL anyway.
You are lucky all of you using a create-table to true, and not worrying about unknow-pk's. But enterprise applications cannot work with a database created from scratch, but rather deal with data migration between old mainframes and new internet architectures and so on...
So, I cannot tell you if you are correct or not. You are not the only one not using an unknow-pk tag with database generated key. I don't know the rule for that (Is it specific to MySQL or specific that the table is created by JBoss or not).
It could be usefull if a JBoss expert can explain this mystery !
The main goal is that our applications are running, isn'it ? -
10. Attempt to get lock ref with a null object
saranggore Mar 23, 2005 3:12 PM (in response to vamsi27e1508)We are trying to deploy EJB 1.1 beans in EJB 2.0. and get this exception. can anyone suggest a solution?