I'm using SimpleJdbcInsert object for inserting new record into Oracle 10g database. Table consists of two columns. id for pkey, and name for description. I wanna use usingGeneratedKeyColumns("id") method to generate pkey for insert statement. For this purpose, I'm creating a new instance with this statement:
And create method of my dao impl like this:Code:SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource) .withTableName("TPaymentOrgSector") .usingGeneratedKeyColumns("id");
Also createParameterSource method:Code:Number newKey = this.simpleJdbcInsert.executeAndReturnKey(createParameterSource(po)); int newId = newKey.intValue();
in this method, i'm not mapping "id" column. because i want it to be created by Spring. But when i run the code,Code:private MapSqlParameterSource createParameterSource(PaymentOrganizationSector po) { return new MapSqlParameterSource() .addValue("NAME", po.getName()); }
exception occurs. What spring does here if i explicitly set the id column? I'm leaving it null, becase i expect it to be generated somehow by Spring. Am i missing some important point? What is the generation rule here? Do i need a sequence or trigger. I couldn't find any clue in the 2.5 Spring documentation...Code:org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL []; ORA-01400: cannot insert NULL into ("TKRY"."TPAYMENTORGSECTOR"."ID") ; nested exception is java.sql.SQLException: ORA-01400: cannot insert NULL into ("TKRY"."TPAYMENTORGSECTOR"."ID")
Thanks in advance.


Reply With Quote