geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Boynes <>
Subject Re: Success (At Least Partially) with AutoKeyGen + CMP in Nova
Date Thu, 08 Jan 2004 23:38:08 GMT
Brendan W.McAdams wrote:

> OK.
> I got a working instance (Test Case) of CMP working with Sybase ASE.  

Cool :)

> Essentially, I changed the ejbCreate method to be a query instead of an 
> update.  Immediately after the insert, it does a "select @@identity" 
> which fetches the ID which was generated by the insert.  

FYI, SQL Server 2000 supports a batch of the form


which does the insert and returns the identity in a single database call 
rather than two (you access it with Statement.getMoreResults()). Does 
this work for Sybase?

> With a custom AutoGeneratedPKCreateMethod, modified slightly from
> CMPCreateMethod to use ejbCreate as a Query rather than an update

Please can you post the code to the Geronimo Jira.

> For the record, this has to be done as part of ejbCreate, as ejbCreate 
> is responsible according to specs and the monson-haefel book for 
> creating the bean's identity, and setting it up in the database table.  
> As far as I can tell, all this, including 'whats the ID', must be done 
> before ejbPostCreate, which exists primarily for CMR Stuff (I could be 
> wrong here - please correct me if I am).
> This methodology works fine, basically developing on the assumption that 
> the EJB creation classes will setup ejbCreate to be a Query Method with 
> the Server Specific "Fetch generated Identity" code, and simply 
> notifying the CMPOperationFactory that it needs to call 
> AutoGeneratedPKCreateMethod in this case.  A set of classes would 
> ideally be generated with the cmp-rdbms xml parser to do this job.  I've 
> hardcoded CMPOperationFactory at the moment, due to a failure to find an 
> effective way of notifying the Operation Factory that it needs to handle 
> this as a DB generated Primary Key.
> Obviously, UnknownPK detection can be done by looking at return Type.  
> What I need now is a methodology for notifying the CMPOperationFactory 
> that it needs to use the AutoGeneratedPKCreateMethod.  I'm not sure what 
> to do - whether I should put a boolean or some kind of indicator in one 
> of the contexts or container classes; I'm looking for feedback on this.

I would suggest adding a new element to geronimo-ejb-jar.xml (there is 
no cmp-rdbms.xml thingy and we don't really want one) that specifies the 
type of CreateMethod VOP to use for a given signature and the key 
factory that it needs. It may be possible to merge CMPCreateMethod, 
UnknownPKCreateMethod and your AutoGeneratedPKCreateMethod into one 
interface - something like CMPIdentityDefiner which does the necessary 
manipulation of the InstanceData and the UpdateCommand to get/set the 
values for EJB and in the database. Something like

interface CMPIdentityDefiner {
    void defineIdentity(CMPInstanceContext ctx) throws Exception;

as it can get the instance, the InstanceData and the id from the ctx.

> At the moment, I'm having some separate issues with findByPrimaryKey 
> related to the Transaction policy which I'm looking into, but as I said 
> - inserting into the database and then fetching and assigning the 
> identity back to the bean works perfectly.   I'm waiting on feedback 
> about how to make this 'arrangement' more permanent before I proceed.
> I'm thinking in the interim while we work out the questions, and while 
> I'm straightening out these other issues I might like to also take a 
> stab at some prototype classes to define the CMP / Database relationship 
> in XML and automatically setup some of the code, which is done manually 
> now in for example BasicCMPEntityContainerTest.setup  ... Anyone have 
> any feedback or objections to this?

Nope. Good luck, it's a big job :-)


View raw message