Persistence Unit Configuration
Persistence unit configuration is done through the persistence.xml file. A sample file looks like this:
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="oxb-company"> <description>Controls company structure</description> <jta-data-source>java:/oxb-company</jta-data-source> <class>com.oxbsystems.ejb.entity.org.common.address.AddressMap</class> <class>com.oxbsystems.ejb.entity.org.common.address.Address</class> <class>com.oxbsystems.ejb.entity.org.common.role.RoleSet</class> .... more classes <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> <property name="hibernate.hbm2ddl.auto" value="update" /> </properties> </persistence-unit> </persistence>
Three elements should be highlighted:
- exclude-unlisted-classes. You may have more entity beans defined, but this tag helps you deploy to the persistence unit only the specified classes. This is useful when you have multiple persistence units, which allows your application to be more modular.
- property hibernate.hbm2ddl.auto. JBoss will create the database schema automatically based on this property, which can take the following values: validate |update | create | create-drop.
- property hibernate.dialect. This property identifies the SQL dialect, which depends on the RDBMS used.