namnv
namnv

Reputation: 49

is there any way to force mybatis to use setter

I need to do some logic before the value is set from the db with mybatis, however, my list field always has size=0

enter image description here

i really need help, if someone knows please help me, I'm so appreciative

Upvotes: 0

Views: 572

Answers (1)

Jeff Butler
Jeff Butler

Reputation: 991

MyBatis is calling your setter. But it works differently than you might be thinking.

This is the way it works - MyBatis will create an empty list and set it in your POJO. Then, for each row, MyBatis will call getRoleList().add() to fill out the list row by row. MyBatis does not create an internal list of values and then call setRoleList() with a fully populated list.

It is best to use MyBatis objects as simple POJOs. Any other processing should be completed after the objects are returned from MyBatis.

Upvotes: 1

Related Questions