Sorry, I accidentally sent this question to jonas-team instead of
jonas-users.

Here is my question:

I'm using INFORMIX-OnLine with Jonas and want to make use of primary key
values for my CMP-Beans generated by the INFORMIX-Server. This can be done
with a SERIAL column in INFORMIX. I already know that there is no ANSI SQL
way to do this, but as I just use INFORMIX I don't care much about
portability in this respect. I already tried to do the following:

- in the method ejbCreate() I set the primary key field (an Integer) to 0.
This tells INFORMIX to generate a value that is unique in the table an can
be used as a primary key for the table. This works fine so far, but I need
to know which number the server generated for the row just inserted.

- in the method ejbPostCreate() I execute the following code to get the
primary-key value:

    try {
      conn = ... (utility to get a Connection)
      stmt = conn.createStatement();
      ResultSet res = stmt.executeQuery( "select DBINFO( 'sqlca.sqlerrd1' )
from " + Dt10001EB.TABLENAME );
      if( res.next() == false ) {
        throw new CreateException( "Can't determine primary key" );
      }
      int resId = res.getInt( 1 );
      id = new Integer( resId );
      Dt10001EBPK pk = (Dt10001EBPK)entityContext.getPrimaryKey();
      pk.id = id;
      System.out.println( "====> serial = " + resId );
    }
    catch( SQLException ex ) {
      throw new CreateException( ex.toString() );
    }
    catch( javax.naming.NamingException ex2 ) {
      throw new CreateException( ex2.toString() );
    }
    finally {
      try {
        if( stmt != null )
          stmt.close();
        if( conn != null )
          conn.close();
      }
      catch( SQLException ex3 ) {
      }
    }

This code works quite well. But when I try to access fields from this bean
within the same transaction I notice that the bean is loaded from the
database again. This does not happen, when i create a bean with a primary
key != 0. That's why I fear, that Jonas caches the primary key 0 before
ejbPostCreate() is called and wonder if this solution would work in all
circumstances or if I would end up with inconsistent EntityBeans in my
container.

Can someone please clear this up? Is there an easier way to use INFORMIX
SERIALS?

Best Regards,
Albert
*******************************************************************
DELICom DPD Deutscher Paket Dienst GmbH & Co. KG
Wailandtstrasse 1, D-63741 Aschaffenburg
Telefon: +49 / (0)6021 / 492-6039
Fax: +49 / (0)6021 / 492-6502
E-Mail: [EMAIL PROTECTED]
Internet: http://www.dpd.de
*******************************************************************


----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".

Reply via email to