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
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.
In EJB 3.0, except for the enterprise bean type value, every annotation enabled configuration is overriden by ejb-jar.xml file configurations.
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 ... !!!
OCBCD (EJB 3), OCJP (Java SE 6), MCTS (MS SQL Server 2005)
Joined: May 06, 2008
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: @PersistenceContext - overriding injection using configuation file.