• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Primary Key auto generation

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I use Jboss version 3.2.3 and Hypersonic database as the development database. I am trying to create an entry in database QuoteInfo (which only has 2 fields : QuoteID and Desc). quoteid is the primary key column. I want the DB to generate the key for me. The Beans are deployed fine and this is the error from the console when my program calls the create method:
2004-05-11 19:11:01,865 DEBUG [org.apache.struts.action.RequestProcessor] Creating new Action instance
2004-05-11 19:11:01,885 INFO [STDOUT] before calling method create
2004-05-11 19:11:01,885 INFO [STDOUT] inside create method
2004-05-11 19:11:01,885 INFO [STDOUT] inside create method 2
2004-05-11 19:11:01,895 ERROR [org.jboss.ejb.plugins.LogInterceptor] RuntimeException:
java.lang.NullPointerException
at org.jboss.ejb.plugins.cmp.jdbc.JDBCIdentityColumnCreateCommand.executeInsert(JDBCIdentityColumnCreateCommand.java:62)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:287)
TIA
-Vili

$$ -- $$
This is the method that calls the create method:
public boolean quoteCreate() {
boolean authenticate= false;

try{
System.out.println("before calling method create");
quoteInfoLocal = quoteInfoLocalHome.create();
System.out.println("after calling method create");
authenticate= true;
return authenticate;
} catch (CreateException e){
System.out.println("Can't create quote");
return authenticate;
}
}
$$ -- $$
public interface EntityQuoteLocalHome extends EJBLocalHome {

public EntityQuoteLocal create() throws CreateException;
public EntityQuoteLocal findByPrimaryKey(Integer quoteID) throws FinderException;
}
$$ -- $$
EntityQuoteBean:
public abstract class EntityQuoteBean implements EntityBean {

private EntityContext context;

public abstract Integer getQuoteID();
public abstract void setQuoteID(Integer quoteID);

public abstract String getDesc();
public abstract void setDesc(String desc);

public Integer ejbCreate() throws CreateException {
System.out.println("inside create method");
setDesc("Test");
System.out.println("inside create method 2");
return null;
}
public void ejbPostCreate(){
System.out.println("This is where I should get the generated PK???");
}

...
}
$$ -- $$
A portion of jbosscmp-jdbc:
<entity>
<ejb-name>QuoteBean</ejb-name>
<table-name>QuoteInfo</table-name>
<cmp-field>
<field-name>desc</field-name>
</cmp-field>
<cmp-field>
<field-name>quoteID</field-name>
<column-name>quoteID</column-name>
<not-null/>
<auto-increment/>
</cmp-field>
<entity-command name="hsqldb-fetch-key"/>
</entity>
</enterprise-beans>

<entity-commands>
<!-- retrieves generated key of the record inserted into hsql db -->
<entity-command name="hsqldb-fetch-key"
class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCHsqldbCreateCommand">
<attribute name="pk-sql">CALL IDENTITY()</attribute>
</entity-command>
</entity-commands>
$$ -- $$
Hypersonic database script:
create table
quoteinfo(quoteid identity, desc varchar(50));
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
set quoteID zero in ejbCreate(), and try it again!
reply
    Bookmark Topic Watch Topic
  • New Topic