Here's my situation. I have an artists table and a recordings table
in a MySQL database.
The artists table has the columns id and name.
The recordings table has the columns id, name, year and artist_id (a
foreign key to the artists table).
I have Artist and Recording POJO classes.
The Recording class has an Artist field to hold a reference to the
Artist object to which the Recording object belongs.
So now I want to insert a row in the recordings table for a Recording
object.
I do this in my Java code.
sqlMap.insert("insertRecording", recording);
The recording variable holds the Recording object which already has
its Artist field set.
Here's the insert element found in Recording.xml.
<insert id="insertRecording"
parameterClass="com.ociweb.music.Recording">
insert into recordings (name, year, artist_id)
values (#name#, #year#, #artist#)
<selectKey resultClass="int" keyProperty="id">
select last_insert_id() as id
</selectKey>
</insert>
I get this error.
[java] --- The error occurred in Recording.xml.
[java] --- The error occurred while applying a parameter map.
[java] --- Check the insertRecording-InlineParameterMap.
[java] --- Check the parameter mapping for the 'artist' property.
[java] --- Cause: java.lang.NullPointerException
Is iBATIS supposed to be able to get the key value from the Artist
object automatically?
I'm guessing the problem is in the last entry in "values( ... )", but
I don't know what to do differently.
I already verified that the Artist field in the recording isn't null
and the Artist object it points to does have an id attribute value.