aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes @PersistenceContext - overriding injection using configuation file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "@PersistenceContext - overriding injection using configuation file." Watch "@PersistenceContext - overriding injection using configuation file." New topic
Author

@PersistenceContext - overriding injection using configuation file.

Tomasz Wolak
Greenhorn

Joined: May 06, 2008
Posts: 10
Hi:
I thought that you should be able to override @PersistenceContext annotation using ejb-jar.xml file. Either I am doing something wrong or there is another issue that I am not aware of.
Simple concept: to learn innards of EJB I created a very simple eCommerce app. The store has two diffrent sources of inventory (let say we can sell shoes and shirts). To manage the inventory I created an inventory manager. You need separate manager to manage each inventory source. Since the managers perform the same functions and only differ in which inventory source they manipulate I only need one class and I'll configure two different instances. Here is my setup:
Code for the Manager

Code for JSF bean that calls the manager:

ejb-jar.xml


I am deploying on Jboss5.0 and the server comes up clean, there are two beans registered, I have two different datastores configured and accessible. However, when I try to run it I always end up creating the new stock in ONE database ("InvShoes") so the one that was injected using @PersistenceContext annotation. I can fix this really easy if I remove the @PersistenceContext(unitName = "InvShoes") annotation from the bean. Therefore, it appears that @PersistenceContext is not being overwritten by the values in the ejb-jar.xml. It was my understanding that the configuration file always trumps the annotation so what is going on here?
Appreciate your input.
Tomasz
Akshay Sahu
Greenhorn

Joined: Sep 04, 2009
Posts: 26

Hi Tomasz Wolak,

In EJB 3.0, except for the enterprise bean type value, every annotation enabled configuration is overriden by ejb-jar.xml file configurations.

Example:
An enterprise bean annotated stateless cannot be overriden as Stateful at ejb-jar.xml file.


Your query, code and question looks ambigious to me.

I request you to be more clear in your question so that I can help you out ... !!!

Akshay Sahu
OCBCD (EJB 3), OCJP (Java SE 6), MCTS (MS SQL Server 2005)
Tomasz Wolak
Greenhorn

Joined: May 06, 2008
Posts: 10
Hi:
The concept is very simple: one class definition, two references each defined in ejb-jar.xml. Even though references have been configured to use different persistence context (InvShoes/InvShirts) they both use the persistence context that was injected using the annotation (InvShoes). The only way I get the reference to use the configured persistence context is to remove the annotation that injects the persistence context.
Given the server I use (Jboss 5) jdk 1.6 and ebj-jar.xml definition why is configuration NOT overriding the injection via annotation.
Not sure how much simpler I can make this.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: @PersistenceContext - overriding injection using configuation file.