• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ejb-spring-hibernate

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys.

For a few day I'm trying to solve a small problem.
So, I have a Spring-Hibernate application.
I've done one EJB to expose the services.
With jUnit everything is OK. I'm loading the application context like this:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/applicationContext.xml" })
@Transactional
@TransactionConfiguration(defaultRollback = false)
public class TestPatientServiceImpl {
.......
}

The EJB is in one modul, the rest in another modul. (jar file)
The problem is that I don't know how to load the applicationContext.xml from my EJB (with the spring beans and hibernate sessionFactory declaration).

Now when I'm trying to call my services from EJB, this (this is in my spring module, another modul than the ejb modul) does not work anymore

@Autowired
@Qualifier("xmlLanguageService")
private XmlLanguageService xmlLanguageServ;


this above does not work.


Any ideas?

Thanks.
Corneliu.
[ October 20, 2008: Message edited by: Corneliu Croitoru ]
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corneliu,

This looks very specific to Spring framework than EJB. I will move this to an appropriate forum where you might get an answer.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, usually Spring apps might call EJBs, but Very rarely the other way around, because people go to Spring so that they do not need to use EJBs.

SPring has <jee> namespace for looking up EJBs in your Spring application, but it can't do anything the other way around. You can expose your services as Corba. "RMI over IIOP", which is what EJBs use.

However, I would more question the design of using EJBs to front Spring, when you can expose Spring beans remotely in many other POJO based ways.

Mark
 
Gigi Kent
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I'm using ejb through spring.
In my ejb bean I have something like


and a method to call something from my app
 
Gigi Kent
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I think I'm managed to do it.

In my ejb bean I have this:

code:

public void setSessionContext(SessionContext sessionContext) {
super.setSessionContext(sessionContext);
setBeanFactoryLocator(ContextSingletonBeanFactoryLocator.getInstance());
setBeanFactoryLocatorKey(PRIMARY_CONTEXT_ID);
}



Im my beanRefContext.xml I have this:

code:



<beans>
<bean id="businessBeanFactory" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list>
<value>applicationContext.xml</value>
</list>
</constructor-arg>
</bean>
</beans>



applicationContext is the xml with all my bean to use. I think Spring finds this file, because I have a

code:


getBeanFactory().getBean(BEAN_NAME);



and I have no error, so it must find the xml file.

Now in my service layer I have something like

code:


@Autowired
@Qualifier("detailedPatientDaoService")
private DetailedPatientDao detailedPatientDao;



and I have a error java.lang.NullPointerException

So I'm guessing that it cannot do the injection.

Any ideas?

Thanks.
Corneliu
 
Gigi Kent
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've managet to see the log from my weblogic, and I see the folowing error:



In my service layer, my methode have this



I don't know what I'm missing.

Please, any ideas?

Thanks.
Corneliu
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have never seen an ApplicationContext object declared as a <bean> in xml, it is the ApplicationContext object that reads the xml file for bean declaration, not reading in itself to itself. So, why are you doing it that way? Just curious.

What object are you creating in code to read in that xml file?

Unless you are in the Web environment, code is usually

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");

Mark
 
Gigi Kent
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Juste curios. Do you know EJB?
If yes, you should know that using setBeanFactoryLocator we are loading the xml file .

I apreciate to have answers from people who know not from people that never worked with it.

Corneliu.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Corneliu Croitoru:
Juste curios. Do you know EJB?
If yes, you should know that using setBeanFactoryLocator we are loading the xml file .

I apreciate to have answers from people who know not from people that never worked with it.

Corneliu.



8 Years of EJB experience form 1.x to 2.x to EJB3, And I find your comment a little rude, our biggest rule here is be nice. I will leave you a bit of slack on this first offense. I am very nice about that.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, you are accessing the Spring beans from EJBs, so your client is calling EJBs to get to your Spring Beans/services.

My comment is it seems that you are defeating the purpose of using Spring instead of EJBs. What benefits are you getting from the EJBs that you can't get from Spring alone in your environment?

Mark
 
Gigi Kent
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, the idea is that I have a service layer, and through EJB I want to expose some methods, in a Weblogic 9.2 to external clients. So, other applications can connect to it , and do some stuff.
I'm using EJB because I have another app who can connect it self only to an EJB. So, EJB is not my choise.

So they (the apps) retrieve the EJB via a JNDI variable, and call one or more methods.
Actually, I think my problem is not the transaction but maybe Weblogic 9.2 cannot handle with the spring annotations (like @Autowire).

I will try to replace the @Autowire with the old fashion spring injection to see if this works. If it will, this is bad news, because I will have to change my code.

PS: Sorry for my previous message

If this will do the trick, I'll post it.

Corneliu.

[ October 23, 2008: Message edited by: Corneliu Croitoru ]
[ October 23, 2008: Message edited by: Corneliu Croitoru ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So, EJB is not my choise.



Thanks, I actually should have asked that question up front. Sorry.

OK, so yes, you seem to have the configuration correct.

Something I noticed in some documentation. It stated,


In the above example, the ServicesConstants.PRIMARY_CONTEXT_ID constant would be defined as follows:
public static final String ServicesConstants.PRIMARY_CONTEXT_ID = "businessBeanFactory";



Because I don't see a ServicesConstants class in the Spring Javadocs, it looks to be a constant that you declare, if you haven't already. (But also looking at your config, it looks like you already have it declared in your EJB)

I am curious to see how you experiment goes with @Autowire, but I am doubting that to be the cause. Because it is in a BeanFactoryPostProcessor class that handles the @Autowire annotation, in which Weblogic has no control over.

Another obvious question, is can you remote debug your code in your App Server. Do you have it configured so that you can set a break point in your IDE, and check out the code. One in the EJB, and one in the service class

WAIT!, as I am typing my reply, I just saw this

@Autowired
@Qualifier("detailedPatientDaoService")
private DetailedPatientDao detailedPatientDao;

Are you sure the Qualifier name is the name of the bean that you want injected? Trying to inject a Service into a DAO reference. Check higher up in your server logs to see if you don't have an expection earlier that the ApplicationContext failed to be created.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But then the odd question, is why is your JUnit test still passing? Are you stubbing or mocking out the DAO?

Mark
 
Gigi Kent
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jUnit tests, are out of weblogic, in local.
I'm testing only the service layer, in my eclipse environement.
So....
I don't know.

I just replaced, the @Autowired with the old fashion injection way (via setter method) and now it's working.

So, the my conclusion is that there is a problem with weblogic 9.2 & @Autowire annotations.



Corneliu.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Corneliu Croitoru:
The jUnit tests, are out of weblogic, in local.
I'm testing only the service layer, in my eclipse environement.
So....
I don't know.

I just replaced, the @Autowired with the old fashion injection way (via setter method) and now it's working.

So, the my conclusion is that there is a problem with weblogic 9.2 & @Autowire annotations.



Corneliu.



In the old fashion way, are you injecting the same "detailedPatientDaoService" or did you use a different bean name? I mean was the bean name supposed to be "detailedPatientDao" instead, and the @Qualifier just had a typo? So when you did it the old fashion way, you fixed that typo?

I am still thinking that Autowire should still work, I'll ask my co-workers via email.

Mark
 
Gigi Kent
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The bean id is detailedPatientDaoService.

Here

the detailedPatientDao is only the name of my attribute.
By any chance this could be the problem?


Now I have something like this



So, before using Qualifier I was specifying the bean id.


I'm missing something here?

Corneliu.
[ October 24, 2008: Message edited by: Corneliu Croitoru ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No not at all. Now that I see that indeed the bean id for that Dao does end with "Service".

Now, I have one more curiosity question. OK, the tests 100% pass, right? I also thought that @Autowire could only be on setters or constructors and not instance variables? I could easily be wrong there.

So my curiosity question. Can you try using the @Resource JSR-250 annotation instead of @Autowire, and see if maybe that might work. @Resource("detailedPatientDaoService")

Oh, and one of my co-workers asked which Java version Weblogic is using? No one else answered my email question about whether @Autowire in Weblogic 9 isn't working. Maybe I need to send it to the whole dev team. I will get an answer for you on that.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, it can go on Field, I just checked the javadocs.

Also being stupid here, but in your configuration file that gets deployed with your app, it does have

<context:annotation-config>, right?

Mark
[ October 24, 2008: Message edited by: Mark Spritzler ]
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic