This bug is actually a duplicate of
EJB-224
, but that bug (filed in 2006) was never fixed. It was marked as a duplicate of a bug that was actually different (
EJB-212
), and when
EJB-212
was fixed
EJB-224
remained broken. 7 years later it is still broken.
The title of this should be changed to "exclude-unlisted-classes is not parsed correctly with explicit value," but I can't change it.
I made some mistakes in my original posting but I cannot edit the description, either, so I will revise it here (due to discussion about element defaults here and the identical Spring Framework bug SPR-10767). Please ignore the description and focus instead of this:
In JPA 1.0 AND 2.0, <exclude-unlisted-classes> has the following usage:
-
Omitted means don't exclude / do scan.
-
<exclude-unlisted-classes /> means exclude / don't scan.
-
<exclude-unlisted-classes>false</exclude-unlisted-classes> means don't exclude / do scan.
-
<exclude-unlisted-classes>true</exclude-unlisted-classes> means exclude / don't scan.
A test case is attached. As attached, persistence.xml contains this:
...
<!--<class>com.wrox.site.entities.Author</class>
<class>com.wrox.site.entities.Book</class>
<class>com.wrox.site.entities.Publisher</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>-->
...
Notice that it all is commented out. If you compile and run this (in Tomcat), the entity classes are picked up (which is correct). Change persistence.xml to this (uncommenting just <exclude-unlisted-classes>):
...
<!--<class>com.wrox.site.entities.Author</class>
<class>com.wrox.site.entities.Book</class>
<class>com.wrox.site.entities.Publisher</class>-->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
...
Now run it and the entity classes are NOT picked up, which is not correct. The behavior should be the reverse in this case. Now change the false to true:
...
<!--<class>com.wrox.site.entities.Author</class>
<class>com.wrox.site.entities.Book</class>
<class>com.wrox.site.entities.Publisher</class>-->
<exclude-unlisted-classes>true</exclude-unlisted-classes>
...
And the entities are still NOT picked up, which in this case is correct. So the explicit values are simply being ignored. A quick look at the current code confirms this:
else if ( tag.equals( "exclude-unlisted-classes" ) ) {
persistenceUnit.setExcludeUnlistedClasses( true );
}
My suggested code below resolves this issue:
private void bindPersistenceUnit(ParsedPersistenceXmlDescriptor persistenceUnit, Element persistenceUnitElement) {
...
persistenceUnit.setExcludeUnlistedClasses( false );
NodeList children = persistenceUnitElement.getChildNodes();
for ( int i = 0; i < children.getLength() ; i++ ) {
...
else if ( tag.equals( "exclude-unlisted-classes" ) ) {
persistenceUnit.setExcludeUnlistedClasses( extractBooleanContent(element, true) );
}
...
}
}
...
private static boolean extractBooleanContent(Element element, boolean defaultBool) {
String content = extractContent( element, null );
if (content != null && content.length() > 0) {
return Boolean.valueOf(content);
}
return defaultBool;
}
|