Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is wrong with the PK

Status
Not open for further replies.

IPOz

Programmer
Jul 11, 2001
109
CN
Hi,friends
I used a EntityBean to maniapulate the coffees table in MS SQL server 2000.The interfaces and configuration is as below:

ejb-jar.xml
...
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>CoffeesBean</ejb-name>
<home>example4/CoffeesHome</home>
<remote>example4/Coffees</remote>
<ejb-class>example4/CoffeesBean</ejb-class>

<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>false</reentrant>

<transaction-type>Container</transaction-type>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>CoffeesBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Supports</trans-attribute>
</container-transaction>
</assembly-descriptor>


<resource-ref>
<res-ref-name>jdbc/SQLServerPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>
</enterprise-beans>
</ejb-jar>
...

home interface
...
public interface CoffeesHome extends javax.ejb.EJBHome {
public Coffees create() throws RemoteException, CreateException;
public Coffees findByPrimaryKey(String cofName) throws RemoteException, FinderException;
}
...

remote interface
...
public interface Coffees extends EJBObject {
public RowSet getCoffees() throws RemoteException, SQLException;
public void updateCoffees(RowSet rs) throws RemoteException, SQLException;
}

...
When i called updateCoffees,the system always reported &quot;id may not be null&quot;.

Any suggestions are appreciated! IPO_z@cmmail.com
Garbage in,Garbage out
 
Sorry! the &quot;id may not be null&quot; is thrown when calling the create method:
...
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, &quot;org.jnp.interfaces.NamingContextFactory&quot; );
h.put(Context.PROVIDER_URL,&quot;localhost:1099&quot;);
Context ctx = new InitialContext(h);
System.out.println(&quot;got context&quot;);

Object obj = ctx.lookup(&quot;ejb/Coffees&quot;);
CoffeesHome coffeesHome = (CoffeesHome) PortableRemoteObject.narrow(obj, CoffeesHome.class);
System.out.println(&quot;got home&quot;);
Coffees coffees = coffeesHome.create(); <- raise the errror
...
I have changed the home interface as below:
public interface CoffeesHome extends javax.ejb.EJBHome
{
public Coffees create() throws RemoteException, CreateException;
public Coffees create(String cofName) throws RemoteException, CreateException;
}
the entity bean's create method:
...
public Object ejbCreate() throws CreateException
{
return null;
}
public void ejbPostCreate() throws CreateException
{
}

public Object ejbCreate(String cofName) throws CreateException
{
return null;
}
public void ejbPostCreate(String cofName) throws CreateException
{
}
...
But it always reported &quot;id may not be null&quot; :(

Any suggestions is appreciated! IPO_z@cmmail.com
Garbage in,Garbage out
 
What version of EJB are you working with? 1.0 required ejbCreate() methods to return null while 1.1 and up are required to return a primary key object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top