|glas...@javadesktop.org||Mar 5, 2008 5:53 pm|
|glas...@javadesktop.org||Mar 5, 2008 6:06 pm|
|glas...@javadesktop.org||Mar 5, 2008 6:09 pm|
|Sahoo||Mar 5, 2008 6:14 pm|
|glas...@javadesktop.org||Mar 5, 2008 7:09 pm|
|glas...@javadesktop.org||Mar 5, 2008 7:25 pm|
|Sahoo||Mar 6, 2008 3:27 am|
|glas...@javadesktop.org||Mar 6, 2008 5:44 am|
|Sahoo||Mar 6, 2008 8:58 am|
|glas...@javadesktop.org||Mar 18, 2008 8:10 am|
|glas...@javadesktop.org||Sep 22, 2008 9:00 pm|
|Subject:||Re: PersistenceContext and the verifier|
|Date:||Mar 5, 2008 6:14:13 pm|
Verifier is correct, thee message could be better though. Having said that, where did you read that it is OK to put persistence.xml in META-INF directory of the ear file. If you put persistence.xml in META-INF of ear, it is simply ignored. If you want your persistence-units to be visible all modules in the ear file, then put in a library jar. The easiest way of doing it is add all entity classes and META-INF/persistence.xml into a jar file (say) entities.jar and package it in lib directory of the ear file.
I'm confused about the @PersistenceContext annotation.
If you look at its documentation, it says, about its "name" attribute:
"The name by which the entity manager is to be accessed in the environment
referencing context, and is not needed when dependency injection is used."
OK. So that means that within some SLSB somewhere I can do this:
[code]@PersistenceContext private EntityManager entityManager;[/code] ...instead of this:
[code]@PersistenceContext(unitName="froobyFrobby") private EntityManager entityManager;[/code] ...and then somewhere in my code I can say this:
[code]assert this.entityManager != null;[/code]
...and [i]some[/i] persistence unit's EntityManager will have been injected in
here. (Which one? The specification doesn't say, as far as I can tell.)
So, OK, I throw this EJB into an .ear file and attempt to deploy it with the
verifier on. The verifier yells at me because I've neglected to put a
persistence.xml in my .ear's META-INF directory. My bad. So I do this...and it
Fine so far. (Note that my persistence root is now the .ear file. Note as well
that the name I've picked for my one persistence unit doesn't appear anywhere
else. I think that's legal.)
Now I run the verifier, and among the steaming piles of log information it
deposits on my hard drive is the following:
[code]-------------- FAILED TESTS : --------------
Test Name : tests.ejb.ejb30.PUMatchingEMandEMFRefTest
Test Assertion : For every entity manager referenced in the application,
there must be a matching persistence unit defined using META-INF/persistence.xml
file. Please refer to EJB 3.0 Persistence API Specification section #6.2 for
further information. Test Description : For [
] There is no unique persistence unit found by name [ null ] in the scope of this
component. Persistence units that are visible to this component are [ ].[/code]
O...K. So I consult section #6.2...and I see nothing that looks to me like a
justification for this test. Is there some line in 6.2 somewhere that will tell
me both: (a) why it is that I don't have to supply a "unitName" attribute to my
@PersistenceContext annotation, even though (b) it is required that this unnamed @PersistenceContext somehow "link up" with
a named persistence unit in my persistence.xml file?
The other thing that bothers me a bit here is that the EJB jar that failed the
test can't "see" any persistence units, even though there is one defined in its
containing ear's META-INF/persistence.xml file.
So, then, three questions:
1. What persistence unit is supposed to be selected when one uses a simple
@PersistenceContext annotation (i.e. one does not supply a unitName attribute)? 2. What is the verifier trying to do, and where did it get its rules in this
department? 3. How does one make an .ear-scoped persistence.xml file visible to the
components in the .ear, if not by putting it in $EAR_ROOT/META-INF?
The reason I'm loath to put a persistence context with a unit name in here is
that I don't want to specify it at the "library" level. That is, I have a
(hopefully) reusable SLSB in a library that, by definition, doesn't know what
application it's going to be part of. So I annotate its entityManager field
with a raw @PersistenceContext annotation.
I hope this all makes sense; thanks for reading.
Best, Laird [Message sent by forum member 'ljnelson' (ljnelson)]