We're updating the issue view to help you get more done. 

change the "exclude-unlisted-classes" behavior in Java SE environments

Description

In JPA 1.0's persistence.xml, <exclude-unlisted-classes> defaulted to false (providers always scanned for entities). As of JPA 2.0, <exclude-unlisted-classes> was changed to default to true. However, Hibernate EntityManager does not honor this. See lines 219-221 of PersistenceXmlParser.java:

1 2 3 else if ( tag.equals( "exclude-unlisted-classes" ) ) { persistenceUnit.setExcludeUnlistedClasses( true ); }

This has two consequences:

  1. If you omit <exclude-unlisted-classes>, Hibernate will scan for entities, which is not compliant. Hibernate should default to the right value based on the JPA version.

  2. If you intentionally add <exclude-unlisted-classes>false</exclude-unlisted-classes> to persistence.xml to enable scanning, Hibernate will disable scanning, which is downright incorrect.

This probably makes more sense:

1 2 3 4 5 6 7 8 9 10 11 else if ( tag.equals( "exclude-unlisted-classes" ) ) { persistenceUnit.setExcludeUnlistedClasses( extractBooleanContent(element, !isJpaGte20) ); } ... 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; }

I don't know where the imaginary isJpaGte20 variable would come from.

Environment

None

Status

Assignee

Brett Meyer

Reporter

Nick Williams

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Time tracking

1h

Components

Affects versions

4.3.0.Beta3
4.2.3
4.1.12
3.6.10
4.0.1

Priority

Major