0

Strange I couldn't find this easy answer in stackoverflow or mybatis guide. Thank you for those who is trying to help.

I have a class like this

Class One {
String name;
}

Class Two {
String name2;
One one;
}

I am using MyBatis @Update annotaion.

@Update("UPDATE One SET " +
            "name=#{name}")
int updatefirst(Two two);

@Update("UPDATE Two SET " +
            "name2=#{name}")
int updatesecondname(Two two);

How do I include the inner property that updates the foreign table one from the above query when I call updatesecondname?

Any help greatly appreciated.

Nithin Devang
  • 69
  • 1
  • 8
  • Unlike ORMs, MyBatis does not insert/update child objects automatically. This [answer](https://stackoverflow.com/a/23921307/1261766) may help. – ave Sep 07 '20 at 02:12
  • Thank you, so we should manage that ourselves? Looks like missing product feature as it has that feature for select. – Nithin Devang Sep 11 '20 at 19:28
  • Yes, you need to manage it manually. As MyBatis is SQL-centric, there is a difference between mapping select result and inserting/updating tables. You should check out JPA/Hibernate. You might like its approach better. – ave Sep 11 '20 at 21:15
  • Thanks, I avoided JPA/Hibernate as I found it very bulky for AWS Lambda. Thank you for the reply, I will manage it myself. – Nithin Devang Sep 18 '20 at 05:35

0 Answers0