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: firstname.lastname@example.org | 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
01:09:49,408 DEBUG [EJBHomeFactory] Getting local home: java:comp/env/ejb/local/
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/
01:09:49,538 DEBUG [CustomerEJB] Executing SQL: select CUSTOMER_ORA_SEQ.nextval fr
01:09:49,659 DEBUG [CustomerEJB] Create: pk=9
01:09:49,659 DEBUG [CustomerEJB] Executing SQL: SELECT COUNT(*) FROM CUSTOMER WHER
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")
Any updates on this? Thanks.
I have successfully generated primary key by using JBOSS 3.2.3 's entity-commands features.
jbosscmp-jdbc looks like this:
<entity-command name="Oracle-sequence" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCOracleCreateCommand">
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.
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.