Skip to content

Which Mapper annotation to use?

Muhammad Hewedy edited this page Apr 9, 2017 · 6 revisions

spwrap comes with 3 types of Mapper annotations @Mapper, @Scalar and @AutoMapper.

All the mapping done in spwrap, done via the Mapper interfaces (ResultSetMapper and TypedOutputParamMapper).

The point is, all of the 3 annotations allow creating and passing of objects that implement the two Mapper interfaces.

@Mapper: let you create manually the Mapper class and pass it for you.

@Scalar and @AutoMapper: create and pass the Mapper Object for you, and the difference between the both is @Scalar works only if you have Single output parameter, and @AutoMapper works if you have a ResultSet.

NOTE: You can use only one of the three annotation on a method, you cannot mix between them.

So, my advice is; If Your stored procedure returns:

  • Both output parameters and result set, then use @Mapper.
  • a List of output parameters without a result set, then use @Mapper.
  • a Single output Parameter without a result set, then use @Scalar.
  • a Result Set of more than 1 column without output parameters, then use @Mapper.
  • a Result set of 1 Column without output paraneters and you do NOT have spring-jdbc or commons-dbutil on you classpath, then use @Mapper.
  • a Result set of 1 Column without output parameters and either spring-jdbc or commons-dbutil on you classpath, then use @AutoMapper.