Creating a JPA configuration file

We will use an EJB 3.0 entity bean for object/relational mapping in the Spring MVC application. The springmvcsrcmain esourcesMETA-INFpersistence.xml configuration file in the jboss-springmvc project was created when we created the Spring MVC project. The persistence.xml file specifies a persistence provider to be used for object/relational mapping of entities to the database. Specify a persistence unit using the persistence-unit element. Set transaction-type to JTA (default). Specify the persistence provider as the Hibernate persistence provider, org.hibernate.ejb.HibernatePersistence. Set the jta-data-source element value to the java:jboss/datasources/MySQLDS data source that we created earlier. The DDL generation strategy is set to create-drop using the hibernate.hbm2ddl.auto property. With the create-drop strategy, the required tables are created and dropped. The hibernate.show_sql property is set to false, implying that all SQL statements be output, which is an alternative method to debugging. The hibernate.dialect file is set to org.hibernate.dialect.MySQLDialect for the MySQL database. The persistence.xml configuration file is listed in the following code:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="         http://java.sun.com/xml/ns/persistence         http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="primary" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>
    <class>org.jboss.springmvc.model.Catalog</class>
    <exclude-unlisted-classes />
    <properties>
      <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/mysql/persistence" />
      <!-- Properties for Hibernate -->
      <property name="hibernate.hbm2ddl.auto" value="create-drop" />
      <property name="hibernate.show_sql" value="false" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
    </properties>
  </persistence-unit>
</persistence>

The JPA specification does not require a persistence provider to create tables even if the hibernate.hbm2ddl.auto property is set to create-drop or create. The Hibernate persistence provider supports creating tables.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset