Also, doing a select max()... for these types of things is dangerous
and has concurrency problems. Don't do it!
I would define a sequence for the companyid field, and write the
insert so that it pulls the value from the sequence.
Then with the brand new MyBatis 3.1, you can return more than one
generated column in the JDBC3 key generator if your driver supports
it:
<insert id="insertCustomer" useGeneratedKeys="true"
keyProperty="id,customernumber" keyColumn="id,customernumber">
insert into customer(..., customernumber,...) values(...,sequence.nextval,...)
</insert>
If this doesn't work with your DB, I would still try to use a sequence
for the customer number, but you may need to do the select nextval
first before you insert.
Jeff Butler
This is a perfect candidate for a stored procedure. You could bundle
all this together on the server side and just have one MyBatis call.
Jeff Butler