Coder Social home page Coder Social logo

Comments (33)

znzlspt17 avatar znzlspt17 commented on July 22, 2024 1

@hazendaz Hello, I opened a new ticket. #302 (comment)

from cdi.

hazendaz avatar hazendaz commented on July 22, 2024

Possibly using @any might work.

Sent by Outlook for Android

On Thu, Jul 23, 2015 at 1:47 PM -0700, "isaiasbsf" [email protected] wrote:
I have a web application with JSF 2.0, mybatis-3.3.0 and mybatis-cdi-1.0.0-beta2. The fllowing two cases does not work running on WebSphere Application Server 8.5.5.5:

@Inject
private SqlSession session;

or

@Inject
@Mapper
private InerfaceXXXMapper mapper;

Eclipse IDE gives me a warnning at the @Inject mentioned abouve:
"No bean is eligible for injection to the injection point [JSR-299 §5.2.1]"

I have a Producer method with ApplicationScoped:

@ApplicationScoped
@produces
public SqlSessionFactory produceFactory() {...}

When I run my application on WebSphere Liberty Profile V8.5 it woks since it does not have injection points validation at start up. When the application is acessed the @produces method is called and the factory is loaded with session and mapper proxys.This cenario works fine.

But when I run my application on the Application Server Full, it uses the OpenWebBeans CDI Container and it tries to validate all injection points at startup and does not find any class of type "SqlSession" or "InerfaceXXXMapper" being produced. The type produced is "SqlSessionFactory" that holds the proxys for SqlSession and its Mappers registred.

How can I make it work?

Thanks,

Isaias


Reply to this email directly or view it on GitHub:
#19

from cdi.

isaiasbsf avatar isaiasbsf commented on July 22, 2024

I got the same resut:

@Inject
@Any
private SqlSession session;

[7/23/15 20:42:56:172 BRT] 0000007e WebContainerL I WebContainerLifecycle startApplication OpenWebBeans Container is starting...
[7/23/15 20:42:58:058 BRT] 0000007e Extension I MyBatis CDI Module - Activated
[7/23/15 20:42:58:673 BRT] 0000007e BeansDeployer E BeansDeployer deploy
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.apache.ibatis.session.SqlSession] is not found with the qualifiers
Qualifiers: [@javax.enterprise.inject.Any()]

from cdi.

hazendaz avatar hazendaz commented on July 22, 2024

Is your producer class also scoped in application scope?

Sent by Outlook for Android

On Thu, Jul 23, 2015 at 5:05 PM -0700, "isaiasbsf" [email protected] wrote:
I got the same resut:

@Inject
@Any
private SqlSession session;

[7/23/15 20:42:56:172 BRT] 0000007e WebContainerL I WebContainerLifecycle startApplication OpenWebBeans Container is starting...
[7/23/15 20:42:58:058 BRT] 0000007e Extension I MyBatis CDI Module - Activated
[7/23/15 20:42:58:673 BRT] 0000007e BeansDeployer E BeansDeployer deploy
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.apache.ibatis.session.SqlSession] is not found with the qualifiers
Qualifiers: [@javax.enterprise.inject.Any()]


Reply to this email directly or view it on GitHub:
#19 (comment)

from cdi.

isaiasbsf avatar isaiasbsf commented on July 22, 2024

I wasn´t, but now it is and didn´t work.

@ApplicationScoped
public class SqlSessionFactoryProvider {

@ApplicationScoped
@produces
public SqlSessionFactory produceFactory() {...}

It seems like it needs to load the factory at startup so that it doesn´t fail the following validation. Is there a way to load the factory at startup?

at org.apache.webbeans.util.InjectionExceptionUtils.throwUnsatisfiedResolutionException(InjectionExceptionUtils.java:92)
at org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:96)
at org.apache.webbeans.container.InjectionResolver.checkInjectionPoints(InjectionResolver.java:189)
at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:1161)
at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:394)
at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:332)
at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:183)
at org.apache.webbeans.web.lifecycle.WebContainerLifecycle.startApplication(WebContainerLifecycle.java:78)
at com.ibm.ws.webbeans.services.JCDIServletContainerInitializer.onStartup(JCDIServletContainerInitializer.java:85)
at com.ibm.ws.webbeans.services.JCDIServletContainerInitializer.onStartup(JCDIServletContainerInitializer.java:85)
at com.ibm.ws.webbeans.services.JCDIServletContainerInitializer.onStartup(JCDIServletContainerInitializer.java:85)

from cdi.

ilkomiliev avatar ilkomiliev commented on July 22, 2024

It doesn't work for me too. I'm on WAS 8.5.5.3 with mybatis-cdi 1.0.0-beta3. Same errors at start-up.

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

Hi @isaiasbsf and @ilkomiliev thanks for reporting this, can you give a try with beta5? Take into accout there are breaking changes: http://www.mybatis.org/cdi/changes.html

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

I have tested beta5 with Payara 4.1 (Glassfish 4.1), TomEE-Plus 7.0.1, WildFly 10.1.0
Please take a look at the code (bare minimum): https://github.com/mnesarco/mybatis-cdi-samples
Can you please test it against WAS?

from cdi.

mcbeelen avatar mcbeelen commented on July 22, 2024

In version beta6 (SNAPSHOT for now) a fix for issue #40 was implemented, which solved the UnsatisfiedResolutionException in WebBeans. This fix might solve the WebSphere issues as well.
Could you please verify?

  1. Please build the cdi-project locally.
  2. Upgrade the version of the mybatis-cdi dependency to 1.0.0-beta6-SNAPSHOT in your application.
  3. Adjust your code to adapt to the breaking changes: http://www.mybatis.org/cdi/changes.html
  4. Deploy your application.
  5. Test and provide feedback.

Cheers,
Marco

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

Hi @isaiasbsf , @ilkomiliev , can you help us testing if beta6 fixed the issue?

from cdi.

ilkomiliev avatar ilkomiliev commented on July 22, 2024

from cdi.

isaiasbsf avatar isaiasbsf commented on July 22, 2024

Hi,

We had to look for another solution since it took too long to solve. However, I got a copy of the project from the time we were using MyBatis CDI, upgraded my dependencies to mybatis-3.4.2.jar / mybatis-cdi-1.0.0-beta6.jar and adjusted the code to the breaking changes:

@Mapper annotation is now mandatory in Mapper Interfaces and forbidden in injection points.
@SessionFactoryProvider is now mandatory in SqlSessionFactory producers.

The server started up ok, but when I tried to access a bean which injects a service that has a Mapper interface injected, I get the following error:

Caused by: java.lang.IllegalStateException: Unable to access CDI
at javax.enterprise.inject.spi.CDI.current(CDI.java:65)
at org.mybatis.cdi.CDIUtils.findSqlSessionFactory(CDIUtils.java:47)
at org.mybatis.cdi.SerializableMapperProxy.getMapper(SerializableMapperProxy.java:60)
at org.mybatis.cdi.SerializableMapperProxy.(SerializableMapperProxy.java:47)
at org.mybatis.cdi.MyBatisBean.create(MyBatisBean.java:116)
at org.apache.webbeans.component.third.ThirdpartyBeanImpl.create(ThirdpartyBeanImpl.java:93)
at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:862)
at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:742)
at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:324)
at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:862)
at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:742)
at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:324)
at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at org.apache.webbeans.context.creational.BeanInstanceBag.create(BeanInstanceBag.java:81)
at org.apache.webbeans.context.AbstractContext.getInstance(AbstractContext.java:179)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:154)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:114)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:108)
at br.com.sodexo.araras.gestaosistema.gestaoacesso.mbean.PesquisarUsuarioMBean_$$javassist_10.loadView(PesquisarUsuarioMBean$$_javassist_10.java)

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

Hi @isaiasbsf ,

Caused by: java.lang.IllegalStateException: Unable to access CDI
at javax.enterprise.inject.spi.CDI.current(CDI.java:65)

Sounds like a container / configuration problem. Do you have a bean.xml file properly placed? Can you share your code? I am trying to solve this in the darkness.

from cdi.

isaiasbsf avatar isaiasbsf commented on July 22, 2024

Yes I do. CDI is working in the project, except for the bean I changed to inject the Mapper interface directly in the new way according to the breaking changes. My project uses JSF with @ConversationScoped beans.

In my SqlSessionFactoryProvider.java I have two providers:

@ApplicationScoped
@produces
@ArarasFactory
@SessionFactoryProvider
public SqlSessionFactory produceArarasFactory() {...}

@ApplicationScoped
@produces
@ArarasSegFactory
@SessionFactoryProvider
public SqlSessionFactory produceArarasSegFactory() {...}

@ArarasFactory and @ArarasSegFactory are just qualifiers to resolve ambiguities.

In my conversationScoped bean I have:

@nAmed
@ConversationScoped
public class CadastroUsuarioMBean {
....
@Inject
private UsuarioService service;

In my service implementation I have:

public class UsuarioServiceImpl implements UsuarioService, Serializable {
....
@Inject @ArarasSegFactory UsuarioMapper usuarioMapper;

In this Mapper interface I Have:

@Mapper
public interface UsuarioMapper extends Serializable {
....
}

If I change the service implementation to inject the SqlSessionFactory instead of the Mapper interface it works, but than I lose the transactional features of MyBatisCDI, which is the reason I wanted to use.

public class UsuarioServiceImpl implements UsuarioService, Serializable {
....
@Inject @ArarasSegFactory SqlSessionFactory sessionFactorySeg;
....
sessionFactorySeg.openSession().getMapper(UsuarioMapper.class).buscarUsuarios(param);

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

Ok. Sounds like a "Passivation issue with the Conversation Scope" I have commited a fix for Issue #45 and it can be related. Please try beta7-snapshot. It works with payara and tomee.

from cdi.

isaiasbsf avatar isaiasbsf commented on July 22, 2024

I didn't find beta7 in Maven central.

from cdi.

hazendaz avatar hazendaz commented on July 22, 2024

@mnesarco Please take a look at the change I made to make serialization tests pass. If that seems appropriate, I can release beta7.

@isaiasbsf Are you ok if we force java 7 usage?

from cdi.

isaiasbsf avatar isaiasbsf commented on July 22, 2024

No problem, we're already using Java 7.

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

@hazendaz your addition is ok. (I have removed Serializable by accident)

from cdi.

hazendaz avatar hazendaz commented on July 22, 2024

@isaiasbsf I have released 1.0.0-beta7. It should be available via poms immediately and will show in maven central in a couple of hours. Can you try this again and let us know if it works? Thanks.

from cdi.

isaiasbsf avatar isaiasbsf commented on July 22, 2024

@hazendaz I changed to beta 7 but got the same error:

Caused by: java.lang.IllegalStateException: Unable to access CDI
at javax.enterprise.inject.spi.CDI.current(CDI.java:65)
at org.mybatis.cdi.CDIUtils.findSqlSessionFactory(CDIUtils.java:46)
at org.mybatis.cdi.SerializableMapperProxy.getMapper(SerializableMapperProxy.java:57)
at org.mybatis.cdi.SerializableMapperProxy.(SerializableMapperProxy.java:44)
at org.mybatis.cdi.MyBatisBean.create(MyBatisBean.java:116)
at org.apache.webbeans.component.third.ThirdpartyBeanImpl.create(ThirdpartyBeanImpl.java:93)
at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:862)
at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:742)
at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:324)
at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:862)
at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:742)
at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:324)
at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at org.apache.webbeans.context.creational.BeanInstanceBag.create(BeanInstanceBag.java:81)
at org.apache.webbeans.context.AbstractContext.getInstance(AbstractContext.java:179)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:154)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:114)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:108)

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

@isaiasbsf This is very strange. It works with OpenWebBeans in Tomee. Can you deploy the Sample App just to see if it works? (https://github.com/mnesarco/mybatis-cdi-samples/). TomEE uses OpenWebBeans 1.6.3, maybe WAS uses some different version?

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

@isaiasbsf @hazendaz I have tested it today with WebSphere Application Server Version 16.0.0.4 Liberty and it works out of the box.

from cdi.

isaiasbsf avatar isaiasbsf commented on July 22, 2024

We're using the WebSphere Application Server 8.5.5.3 (Liberty Profile) for development and WebSphere Application Server 8.5.5.5 (Full application server) on production environment. I deployed the sample App (https://github.com/mnesarco/mybatis-cdi-samples/) and got the following error when accessing the web context:

Caused by: javax.servlet.ServletException: SRVE0320E: O filtro [SampleWebFilter] foi localizado, mas ocorreu uma falha na injeção de recursos.
... 3 more
Caused by: com.ibm.wsspi.injectionengine.InjectionException: Unable to obtain an instance for @Inject java.lang.reflect.Field.userMapper: java.lang.NoClassDefFoundError: javax/enterprise/inject/spi/CDI
at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1123)
... 1 more
Caused by: java.lang.NoClassDefFoundError: javax/enterprise/inject/spi/CDI
at org.mybatis.cdi.CDIUtils.findSqlSessionFactory(CDIUtils.java:46)
at org.mybatis.cdi.SerializableMapperProxy.getMapper(SerializableMapperProxy.java:57)
at org.mybatis.cdi.SerializableMapperProxy.(SerializableMapperProxy.java:44)
at org.mybatis.cdi.MyBatisBean.create(MyBatisBean.java:116)
at org.apache.webbeans.component.third.ThirdpartyBeanImpl.create(ThirdpartyBeanImpl.java:93)
... 1 more

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

@isaiasbsf @hazendaz WAS CDI support started in 8.5.5 (CDI 1.0 I suppose), but it was updated to CDI 1.2 in 8.5.5.6.
ref: https://www.ibm.com/support/knowledgecenter/SS7JFU_8.5.5/com.ibm.websphere.wdt.doc/topics/wdt_overview.htm

You need at least CDI 1.1 to use mybatis-cdi.

from cdi.

isaiasbsf avatar isaiasbsf commented on July 22, 2024

It's true, we're using cdi-1.0 since it is the CDI version supported on our version of the application server. I understand now that MyBatis-CDI minimal compliance is cdi-1.1. However, we're not upgrading our application server at this time because of this. The CDI container works for everything else, except for MyBatis CDI. This issue was opened almost 2 years ago and we were using the latest version of WebSphere Application Server at the time. As I said before, we switched to another solution (MyBatis-Guice) and I was just trying to help solve the problem with our version. When we decide to upgrade our application server in the future, we'll consider switching back to MyBatis-CDI.
Thanks for your time.

from cdi.

hazendaz avatar hazendaz commented on July 22, 2024

from cdi.

mnesarco avatar mnesarco commented on July 22, 2024

@isaiasbsf @hazendaz Ok Guys, Thanks for your help. I am closing this now. I have updated the README with info about the CDI versions supported.

from cdi.

znzlspt17 avatar znzlspt17 commented on July 22, 2024

I have an UnsatisfiedResolutionException problem with the mapper like isaiasbspf.

Was there a solution to this problem afterwards?

from cdi.

hazendaz avatar hazendaz commented on July 22, 2024

@znzlspt17 What version of WAS and mybatis-cdi are you using? Based on this thread, you need to be at cdi 1.1 which is least supported version. We have profiles in pleace on github actions to run through all configuration needs from 1.1 to 2.0 with various java configurations. Those are known supported. This thread was in regards to WAS 8.5.5.5 which I'm guessing from context here was still cdi 1.0. I'd sort of hope you were not still trying to use that as it is long vulnerable and well over 5 years old based at this point in time.

from cdi.

znzlspt17 avatar znzlspt17 commented on July 22, 2024

@hazendaz hello im using mybatis 3.5.9, mybatis-cdi 1.1.2, owb 2.0.17, aries cdi 1.1.5 using on java 11 base karaf 4.3.7 Should I create a new post?

from cdi.

hazendaz avatar hazendaz commented on July 22, 2024

@znzlspt17 Yes open new ticket with stack trace of issue you are facing. This ticket is specific to WAS and legacy usage which was noted as resolved in indicating newer version necessary. The library usage you have looks ok.

from cdi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.