wood burning stoves
The moose likes EJB and other Java EE Technologies and the fly likes create method not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "create method not working" Watch "create method not working" New topic

create method not working

Rick Delpo

Joined: Sep 26, 2006
Posts: 3
I have a very simple EJB in Jboss 3.25, windows xp, jdk 5.0, mysql connector J

with files


All my code compiles fine and the connection is container managed. I am new to EJB. When I start the server there are no runtime errors and the container creates the table in the database so the connection is ok. When I invoke my test client, my one and only create method gets the context and a reference to the bean but no insert occurs in the table. Am I missing something in my xml files?

code is as follows:


package com.javasrc.licenseserver.ejb.product;

import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;

public interface ProductHomeRemote extends javax.ejb.EJBHome
public ProductRemote create( Integer id, String name ) throws CreateException,

public ProductRemote findByPrimaryKey( Integer id ) throws FinderException,



package com.javasrc.licenseserver.ejb.product;

import java.rmi.RemoteException;

public interface ProductRemote extends javax.ejb.EJBObject
public String getName() throws RemoteException;
public void setName( String name ) throws RemoteException;


package com.javasrc.licenseserver.ejb.product;

import javax.ejb.*;
import java.util.*;

public abstract class ProductBean implements EntityBean
public Integer ejbCreate( Integer id, String name ) throws CreateException
return null;

public void ejbPostCreate( Integer id, String name )

public abstract Integer getId();
public abstract void setId( Integer id );

public abstract String getName();
public abstract void setName( String name );

public void setEntityContext( EntityContext ctx ) {}
public void unsetEntityContext() {}
public void ejbLoad() {}
public void ejbStore() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbRemove() {}

4) very simple servlet test client..a welcome file called home.html accesses this

test client

package com.javasrc.licenseserver.client;

import java.io.IOException;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.*;
import com.javasrc.licenseserver.ejb.product.ProductHomeRemote;
import com.javasrc.licenseserver.ejb.product.ProductRemote;

public class TestClient extends HttpServlet {

public void init() throws ServletException {


public void service(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

ServletContext sc;
RequestDispatcher rd;
String title = "Servlet interface to EJB";

try {

InitialContext jndiContext = new InitialContext();
System.out.println("Got context");
Object ref = jndiContext.lookup("ProductHomeRemote");
System.out.println("Got reference");
ProductHomeRemote home = (ProductHomeRemote) PortableRemoteObject.narrow(ref,


//insert a new product

Integer primaryKey =new Integer(25);
ProductRemote product = home.create(primaryKey, "sample entry");
catch (Exception ex) {




<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"





<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">



<?xml version="1.0"?>
Rick Delpo

Joined: Sep 26, 2006
Posts: 3
I figured this out on my own. All my code is correct, I forgot to put jbossall-client.jar in the lib folder of my test client app.

Now this leads to another issue, the insert worked and is now in the mysql table but when I tried to recompile my test client with new input parameters I got this runtime exception in jboss:

19:40:12,250 INFO [STDOUT] javax.ejb.DuplicateKeyException: Entity with primary
key 25 already exists

19:45:41,703 INFO [STDOUT] at org.jboss.ejb.plugins.cmp.jdbc.JDBCInsertPKCr
19:45:41,703 INFO [STDOUT] at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCr
19:45:41,703 INFO [STDOUT] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManag
19:45:41,703 INFO [STDOUT] at org.jboss.ejb.plugins.CMPPersistenceManager.c
19:45:41,703 INFO [STDOUT] at org.jboss.resource.connectionmanager.CachedCo
19:45:41,703 INFO [STDOUT] at org.jboss.ejb.EntityContainer.createHome(Enti

.......more but not to bore you with it ..............

The server thinks I still have the same data. I even tried rebooting and going back to make sure I had a NEW test client class file and it still returned the same info.

Thanks in advance for helping a newbie
Rick Delpo

Joined: Sep 26, 2006
Posts: 3
sorry to bother everyone.

just figured it out again.

my test client class was in both the server jar file and the client jar file. I took it out at the server level.

apparently cmp was looking at the server jar first and seeing my test client class there, the one I did not change, and of course it showed a duplicate primary key.
I agree. Here's the link: http://aspose.com/file-tools
subject: create method not working
It's not a secret anymore!