-
1. Re: Help with auto-increment and entity-command
sysuser1 Apr 19, 2003 1:21 AM (in response to sysuser1)When I turned on debug, it shows that the pk-sql for the sequence was being executed and the pk sequence number was being generated. But it was not used for the primary key when doing the insert. Has anyone been successful with this auto-increment ?
The debug shows as follows:
01:09:49,408 DEBUG [AdminSessionEJB] Add Customer: Customer[Id: null | Name: Troy
Jones | DOB: 08/04/1975 | Gender: Male | SSN: 111111111 | Phone:
1111111111 | Email: aaa@aol.com | Address[Id: null | StreeName1: 1st st |
StreetName2: | City: NY | State: NY | ZipCode: 11111 | Country: USA]]
01:09:49,408 DEBUG [ServiceLocator] Getting new local home for java:comp/env/ejb
/local/address
01:09:49,408 DEBUG [EJBHomeFactory] Getting local home: java:comp/env/ejb/local/
address, com.bea.medrec.entities.AddressLocalHome
01:09:49,418 DEBUG [findByEmail] Executing SQL: SELECT t0_o.id FROM CUSTOMER t0_o
WHERE t0_o.email = ?
01:09:49,538 DEBUG [AdminSessionEJB] Customer not found. Creating new customer.
01:09:49,538 DEBUG [ServiceLocator] Getting cached local home for java:comp/env/
ejb/local/address
01:09:49,538 DEBUG [CustomerEJB] Executing SQL: select CUSTOMER_ORA_SEQ.nextval fr
om DUAL
01:09:49,659 DEBUG [CustomerEJB] Create: pk=9
01:09:49,659 DEBUG [CustomerEJB] Executing SQL: SELECT COUNT(*) FROM CUSTOMER WHER
E id=?
01:09:49,809 DEBUG [CustomerEJB] [CustomerEJB.ejbCreate] Executing SQL: INSERT INT
O CUSTOMER (id, address_id, dob, email, first_name, gender, last_name, middle_nam
e, phone, ssn) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
01:09:49,909 ERROR [CustomerEJB] Could not create entity
java.sql.SQLException: ORA-01400: cannot insert NULL into ("ABC"."CUSTOMER"."ID")
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1892)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:109
3) -
2. Re: Help with auto-increment and entity-command
bwilly Jan 14, 2004 10:01 PM (in response to sysuser1)Any updates on this? Thanks.
-
3. Re: Help with auto-increment and entity-command
marcoyeung Jan 15, 2004 2:23 AM (in response to sysuser1)hi,
I have successfully generated primary key by using JBOSS 3.2.3 's entity-commands features.
jbosscmp-jdbc looks like this:
<enterprise-beans>
.......
<cmp-field>
<field-name>id</field-name>
<column-name>ID</column-name>
<auto-increment/>
</cmp-field>
........
<entity-command name="Oracle-sequence"/>
</enterprise-beans>
<entity-commands>
<entity-command name="Oracle-sequence" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCOracleCreateCommand">
SEQUENCE_EJB
</entity-command>
</entity-commands>
SEQUENCE_EJB is a sequence in my Oracle 8.1.7 db.
Which version of JBOSS are you using??, I think the above code suitable for JBOSS 3.2.2. and 3.2.3.
==Hope the above helps, here comes my problem, pls HELP===
If my table has a trigger to generate primary key for SQL statment, when BEAN get a sequence and then insert back to this table, it will fire the trigger in the table too. cause the primary key number advance 1 more, so in my table, I have primary key like : 1, 3, 5, 7 .........
is there any one know how to solve this if I what to use JBOSS auto-key generation for BEAN and also trigger auto-key generation for normal SQL statement in one table.
Pls HELP, my system can't lost primary key sequence.
many thanks
Marco -
4. Re: Help with auto-increment and entity-command
sbrbot Jan 15, 2004 8:53 AM (in response to sysuser1)You cannot just define <unknown-pk> for your PK field in DD file. <unknown-pk> requires diferent approach in bean class development defining primary key as an java.lang.Object.