0

I am new to iBatis. In my project we are using iBatis to persist the java objects in Oracle DB. I have a class, ClassA, which is having 3 columns : id, name and description. The data is going to be persisted in TableA. There is a sequence in DB to generate the value for id column in this table. We wrote the insert statement to this table as follows,

<insert id="insertTableA" parameterClass="com.ClassA">
    <selectKey resultClass="java.lang.Long" keyProperty="id">
       SELECT seq_TableA.nextval as id FROM dual
    </selectKey>
    INSERT INTO TableA(ID, NAME, DESCRIPTION) VALUES (#id#, #name#, #description#)
</insert>

This worked fine.

But becaude of our inhouse UI framework limitation we had to change some design. So we need to first generate the id long from sequence, set that value in an instance of ClassA along with name and description and then insert into DB. So in that case the insert statment doesn not need a selectKey attribute. The id, name and description values are in the object. When I updated the query like below, it is throwing Null Pointer Exception.

<insert id="insertTableA" parameterClass="com.ClassA">
    INSERT INTO TableA(ID, NAME, DESCRIPTION) VALUES (#id#, #name#, #description#)
</insert>

How we can insert data into table without using a . I am generating the key from the sequence first , populate the object with all values including the id and trying to call the statement from Java as follows,

getSqlTemplate().insert("process.insertTableA", instanceClassA);

Any pointers are welcome,

Thanks, SD

user184794
  • 1,036
  • 9
  • 15

1 Answers1

0

Just to be sure, did you include a getId() method in your ClassA class so that it will return the value of the id field?

Brian Showalter
  • 4,321
  • 2
  • 26
  • 29