Charles N. Harvey III said:
> It means that something isn't set correctly in the database.
> This has happened to me many times.  It always happens when I turn on
"native" sequencing (IDENTITY in MSSQL or AUTOINCREMENT in MySql). 
Check the PK of your database, it might not be properly set to
increment. Whenever
> this isn't set properly I get -1 and -2 for sequence numbers all the time.

The database is OK -- I tested it directly, and it assigns sequence
numbers correctly.

This is the code; I've added transaction calls for the PB-api, but the
table I'm using this with doesn't have transactions enabled, so those are
effectively just null-ops:

            broker =
PersistenceBrokerFactory.createPersistenceBroker(getPbKey());
            broker.beginTransaction();


            // 1. make sure no user with that username exists
            Criteria c = new Criteria();
            c.addEqualTo("emailAddress", username);
            Query q = QueryFactory.newQuery(getUserInstanceClass(), c);
Collection col = broker.getCollectionByQuery(q);
            if (col.size() > 0) {
                throw new DuplicateUsernameException(username);
            }

            // 2. create the new user and return its object
            User user = (User) getUserInstanceClass().newInstance();
user.setEmailAddress(username);
            user.setPassword(password);
            user.setFirstName(firstName);
            user.setLastName(lastName);
            broker.store(user);

            broker.commitTransaction();

Here's the class descriptor:

<class-descriptor
    class="com.kloognome.accesscontrol.ojb.UserInstance"
    table="ac_users">
    <field-descriptor name="userNbr" column="user_nbr" jdbc-type="INTEGER"
primarykey="true" autoincrement="true" access="readonly"/>
    <field-descriptor name="emailAddress" column="email_address"
jdbc-type="VARCHAR"/>
    <field-descriptor name="password" column="password"
jdbc-type="VARCHAR"/> <field-descriptor name="firstName"
column="first_name"
jdbc-type="VARCHAR"/>
    <field-descriptor name="lastName" column="last_name"
jdbc-type="VARCHAR"/>
</class-descriptor>

I'm using the 1.0.0 release of OJB, if that matters.

I've tried re-creating the table with the "auto_increment" and "primary
key" attributes reversed on the table definition; that didn't change
anything. I've tried forcing the userNbr field on the object to zero; that
didn't change anything.

Any ideas?



-- 
"In discussing [terrorists], 'Capturing their hearts and minds' only makes
sense if by that you mean, literally, capturing their hearts and minds and
putting them in mason jars." -- Jonah Goldberg


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to