Is
In a standard persistence.xml file,
Automatic Class Scanning
However, the Java EE specification 5 includes a jar-file element within persistence.xml that can be used for automatic scanning of persistence classes:
<persistence> <persistence-unit name="UnitName"> <jar-file>MyJarFile.jar</jar-file> <class>com.example.EntityClass</class> </persistence-unit> </persistence>
Hibernate Auto-Detection
If a spec-compliant approach is not preferred, Hibernate supports auto-detection in Java SE environments:
<persistence-unit name="UnitName"> <properties> <property name="hibernate.archive.autodetection" value="class, hbm" /> ... </properties> </persistence-unit>
This property scans for annotated classes and Hibernate mapping XML files to automatically discover entities.
Note: For Hibernate versions prior to 5.1, this requires adding the Hibernate EntityManager Bean 2 module as a dependency.
The above is the detailed content of Is `` Required in `persistence.xml` for Entity Management?. For more information, please follow other related articles on the PHP Chinese website!