Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question/Issue about Mybatis-cdi @Mapper discovery #30

Closed
sander78 opened this issue Feb 19, 2016 · 2 comments
Closed

Question/Issue about Mybatis-cdi @Mapper discovery #30

sander78 opened this issue Feb 19, 2016 · 2 comments

Comments

@sander78
Copy link

Hi there,

We use mybatis-cdi in combination with java8. With the default implementation now possible in interfaces this makes code like this possible.

@Inject
  public ItemRepoResolver(@Any Instance<ItemMapper<?>> itemMappers) {
    this.itemMappers = itemMappers;
  }

So we inject a list of Mappers of type ItemMapper and each mapper can say for which type it can be used. For example:

public interface SavingsAccountMapper extends ItemMapper<SavingsAccount> {

  ..some mapper code...

  @Override
  default Class<SavingsAccount> forType() {
    return SavingsAccount.class;
  }
}

But since we do not use @Inject @Mapper SavingsAccountMapper this mapper is not initialized. We can force this initialization by adding this field but we do not need this.

So my question/issue is. Is is possible to inject a list of Mybatis Mappers without the need to inject them in fields individually?

Thanks,
Sander

@mnesarco
Copy link
Member

Hi Sander,

mybatis-cdi only recognize Mappers injected with @mapped at least once. So
if you have a mapper but you do not inject it with @Mapper somewhere...
mybatis-cdi will ignore it.

Cheers,

Frank.

On Fri, Feb 19, 2016 at 5:39 AM, sander78 notifications@github.com wrote:

Hi there,

We use mybatis-cdi in combination with java8. With the default
implementation now possible in interfaces this maken code like this
possible.

@Inject
public ItemRepoResolver(@Any Instance<ItemMapper<?>> itemMappers) {
this.itemMappers = itemMappers;
}

So we inject a list of Mappers of type ItemMapper and each mapper can say
for which type it can be used. For example:

`
public interface SavingsAccountMapper extends ItemMapper {

..some mapper code...
@OverRide https://github.com/Override
default Class forType() {
return SavingsAccount.class;
}
}
`

But since we do not use @Inject https://github.com/Inject @Mapper
https://github.com/Mapper SavingsAccountMapper this mapper is not
initialized. We can force this initialization by adding this field but we
do not need this.

So my question/issue is. Is is possible to inject a list of Mybatis
Mappers without the need to inject them in fields individually?

Thanks,
Sander


Reply to this email directly or view it on GitHub
#30.

Frank D. Martínez M.

@sander78
Copy link
Author

Okay that's what I figured :)
By the way I just found out it wouldn't work anyway as Mybatis does not accept a default implementation in the interface and will throw an Exception. Too bad.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants