We handled this by creating an entity bean with the fields table_name (pk)
and next_id and a stateless session bean that has a method returnPK. To deal
with transactional issues the method getNextID is declared a required
transaction
in ejb-jar.xml.

 /** returnPk gets the max id from the pktable adds 1 returns it to the
        caller and then updates the pktable with the new highest id */
    public Integer returnPk(String tableName) throws NamingException,
FinderException, RemoteException {
        
        Integer pk = null;
        
        pk = getNextId(tableName);
        return pk;
    }

    /** getNextId() is an atomic transaction that will get the nextId
        update the pktable and then return the id to the caller. */
    
    private Integer getNextId(String tableName)throws NamingException,
FinderException, RemoteException {
     
        Integer oldPk=null;
        Integer newPk=null;
        int pkInt=-1;
        
        PkEntity pkEnt = home.findByPrimaryKey(tableName);
        oldPk = pkEnt.getNextId();
        pkInt= oldPk.intValue();
        ++pkInt;
        newPk = new Integer(pkInt);
        pkEnt.setNextId(newPk);
        return newPk;
    }
        


 snipped of ejb-jar.xml

<assembly-descriptor>
   <container-transaction>
      <method>
         <ejb-name>PkSessionBean</ejb-name>
         <method-name>getNextId</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
   </container-transaction>
</assembly-descriptor>

There is also a more involved project going on through the server-side.com
that you may
want to check out as well. For our needs, however, we feel that the above
method will
work fine.

Hope this helps,

Kevin



Kevin Meldorf
Systems Analyst
WorldTravel BTI
400 Skokie Blvd
Northbrook, IL 60062
Phone: (847) 480-8340
[EMAIL PROTECTED]




_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to