Openjpa ant mapping tool


















The following chapter will illustrate these integration features. Ant is a very popular tool for building Java projects. It is similar to the make command, but is Java-centric and has more modern features. Ant has become the de-facto standard build tool for Java, and many commercial integrated development environments provide some support for using ant build files.

The remainder of this section assumes familiarity with writing Ant build. Enhancer Task. Application Identity Tool Task. Mapping Tool Task. Reverse Mapping Tool Task. Schema Tool Task.

The source code for all the ant tasks is provided with the distribution under the src directory. This allows you to customize various aspects of the ant tasks in order to better integrate into your development environment. All OpenJPA tasks accept a nested config element, which defines the configuration environment in which the specified task will run. Note that excluding the config element will cause the Ant task to use the default system configuration mechanism, such as the configuration defined in the org.

Following is an example of how to use the nested config tag in a build. It is also possible to specify a properties or propertiesFile attribute on the config tag, which will be used to locate a properties resource or file. Embedded Mapping 7. Collections 7. Container Table 7. Element Join Columns 7. Order Column 7. One-Sided One-Many Mapping 7.

Maps 7. Indexes and Constraints 7. Indexes 7. Foreign Keys 7. Unique Constraints 7. XML Column Mapping 7. Stream LOB Support 8. Key Columns 9. Key Join Columns Key Embedded Mapping Examples Mapping Limitations Table Per Class Mapping Extensions Class Extensions Subclass Fetch Mode Strategy Discriminator Strategy Version Strategy Field Extensions Eager Fetch Mode Nonpolymorphic Class Criteria Combine this with a schemaAction of build to generate a script that recreates the schema for the current mappings, even if the schema already exists.

This option is ignored if readSchema is not set to true. Reading the existing schema ensures that OpenJPA does not generate any mappings that use table, index, primary key, or foreign key names that conflict with existing names.

Depending on the JDBC driver, though, it can be a slow process for large schemas. Defaults to false. This means that to add any new foreign keys to a class that has already been mapped, you must explicitly set this flag to true. This means that to add any new indexes to a class that has already been mapped once, you must explicitly set this flag to true.

Defaults to true. The available actions are:. It makes the database schema match your existing mappings. If your provided mappings conflict with a class definition, OpenJPA will fail with an informative exception. No mappings or tables will be changed. An exception is thrown if any mappings are invalid. The mappings generated by the mapping tool are stored by the system mapping factory. The JPA specification defines a comprehensive set of defaults for missing mapping information.

Thus, forward mapping in JPA is virtually automatic. After using the mapping annotations covered in Chapter 12, Mapping Metadata of the JPA Overview to override any unsatisfactory defaults, run the mapping tool's buildSchema action on your persistent classes. The buildSchema action manipulates the database schema to match your mappings. It fails if any of your mappings don't match your object model. To drop the schema for a persistent class, set the mapping tool's schemaAction to drop. The examples below show how to use the mapping tool to generate DDL SQL scripts, rather than modifying the database directly.

This example uses your existing mappings to determine the needed schema, then writes the SQL to create that schema to create. Example 7. This example uses your existing mappings to determine the needed schema.

It then writes the SQL to add any missing tables and columns to the current schema to update. You can configure OpenJPA to automatically run the mapping tool at runtime through the openjpa.

Schema : Details about operations on the database schema. Chapter 3. Logging Prev Part 3. Reference Guide Next. Table of Contents 1. Logging Channels 2. OpenJPA Logging 3. Disabling Logging 4. Log4J 5. Apache Commons Logging 5.



0コメント

  • 1000 / 1000