0

Hi Guys i have a complex object as below and would like to know how to write mapper.xml for the same.

I have knowledge to insert a simple object, but i am not getting this with 2 levels of Hierarchy.

Below is my domain object

class Org{
  id=O1
  str1;
  List<Division>
}

class Divison{
  id = D1
  org = O1
  str2;
  List<Employees>
  List<Managers>
}

class Employees{
 str3;
 id = E1
 divId = D1
}

class Managers{
 str3;
 id = M1
 divId = D1
}

So Org has multiple Divisons, Each Divison has multiple Employees and Managers.

How can i write my mybatis mapper.xml so that i can insert Organization, Divison, Employees and Managers to respective tables in one transaction

Punith Raj
  • 2,164
  • 3
  • 27
  • 45
  • 1
    The question is not clear. Namely, what problem do you have? Why insertion one by one starting from the org, then divisions and so on does not work? – Roman-Stop RU aggression in UA Oct 25 '18 at 08:10
  • Thats right.. i am looking into batch insert http://www.mybatis.org/mybatis-dynamic-sql/docs/insert.html – Punith Raj Oct 25 '18 at 09:37
  • 1
    The batch is to insert in a row multiple records in a table. For the transaction, call all mappers in the same high level method and commit at the end, or annotate the method with @Transactional from your container (Spring, CDI, ...) – blackwizard Oct 29 '18 at 15:10

0 Answers0