Still Unabe to Create Entity Bean
garymarsh Jan 9, 2002 4:25 PMHi,
I previously posted that I was unable to Create an Entity Bean using JBoss 2.4.3 and the MS JDBC Driver. I installed another JDBC Driver, "JSQLConnect" with the same resulting Error.
I have modified the Bean to use a Long as its primary key instead of wrapping it in a PK class. I modified the ejb-jar.xml as follows :
Client Entity Bean
<ejb-name>Client</ejb-name>
com.paye.payroll.ClientHome
com.paye.payroll.ClientRemote
<ejb-class>com.paye.payroll.ClientBean</ejb-class>
<persistence-type>Container</persistence-type>
<!-- prim-key-class>com.paye.payroll.ClientPK</prim-key-class -->
<prim-key-class>java.lang.Long</prim-key-class>
<cmp-field><field-name>clientId</field-name></cmp-field>
<cmp-field><field-name>name</field-name></cmp-field>
<cmp-field><field-name>address</field-name></cmp-field>
<cmp-field><field-name>city</field-name></cmp-field>
<cmp-field><field-name>state</field-name></cmp-field>
<cmp-field><field-name>zip</field-name></cmp-field>
<cmp-field><field-name>taxId</field-name></cmp-field>
<primkey-field>clientId</primkey-field>
False
.
.
.
I have modified my ejbCreate() to return null as was suggested by Sven.
public Long ejbCreate( String name, String address, String city,
String zip, String taxId) throws CreateException,
RemoteException
{
Long number = null;
try
{
InitialContext ictx = new InitialContext();
String propFileName = (String)ictx.lookup("java:comp/env/PayeProperties");
if( this.seqGen == null )
this.seqGen = new SeqGenerator2(propFileName);
if( this.seqGen == null )
log.debug("unable to instanciate a SeqGenerator object");
else
log.debug("We have a SeqGenerator object");
number = new Long(seqGen.generate("Client"));
if( number != null )
log.debug("Got an Autogenerated number");
}
catch(javax.naming.NamingException ne)
{
ne.printStackTrace();
}
catch( Exception e )
{
System.out.println(e.getMessage());
}
this.clientId = number;
this.name = name;
this.address = address;
this.city = city;
this.zip = zip;
this.taxId = taxId;
log.debug("ClientId ="+clientId+
"\n name ="+name+"\n address="+address+
"\n city="+city+"\n zip="+zip+"\ntaxid="+taxId);
return null;
}
======================
The code that I call from my Bean Tester is :
public static void main(String args[]) throws Exception
{
InitialContext iniCtx = null;
ClientHome home = null;
ClientRemote bean = null;
ClientRemote bean2 = null;
Long pk= null;
Object ref = null;
try
{
if( (iniCtx = new InitialContext()) == null)
log.debug("Initial context is null");
else
log.debug("Got initial context");
ref = iniCtx.lookup("payroll/Client");
if( ref == null)
log.debug("Reference object is null");
else
log.debug("Got reference object");
}
catch( Exception e )
{
log.debug("Initializing error :"+e.getMessage());
System.exit(1);
}
try
{
home = (ClientHome) ref;
bean = home.create("Acme Tools","222 Cabot Rd", "Laguna Niguel", "92677", "TXID-123");
//System.out.println("bean = "+bean.getBeanState());
}
catch(...){....}
==================================
and this is the output from the log file.
[PropertyReader] in readInStream() : propFileName = Paye.properties
[PropertyReader] URL for propFile is jar:file:/D:/JBoss-2.4.3_Tomcat-3.2.3/jboss/tmp/deploy/Default/Paye_Payroll.jar/ejb1002.jar!/Paye.properties
[PropertyReader] Properties file was loaded into p
[PropertyReader] p was set to SystemProperties
[ClientBean] We have a SeqGenerator object
[JDBCGenerator] in generate(String seq) : seq =Client
[JDBCGenerator] in generate(String seq) : conn =com.microsoft.jdbc.sqlserver.SQLServerConnection@762fc7
[SeqGenerator2] jdbcGen.generate() made new clientId = 38
[ClientBean] Got an Autogenerated number
[ClientBean] ClientId =38
name =Acme Tools
address=222 Cabot Rd
city=Laguna Niguel
zip=92677
taxid=TXID-123
[Client] TRANSACTION ROLLBACK EXCEPTION:null
Embedded Exception
null; nested exception is:
javax.ejb.EJBException: null
Embedded Exception
null
================
The database is MS SQLServer 2000 and the database table look like this:
clientId BIGINT IDENTITY NO NULLS,
name VARCHAR(50),
address VARCHAR(30),
city VARCHAR(30),
state CHAR(2),
zip CHAR(5),
taxId CHAR(9) ;
Can anyone tell me why I am unable to create this CMP Entity Bean?
Thanks,
Gary