![]() | ![]() |
![]() |
| Project | Ver 1.1 | Ver 1.2 | JDO | JPA | Guides | Tools |
| 1.1 | Preparation | O/R Mapping | Runtime | Extensions | Developer |
Many JDO implementations add various types of information to the tables for persisted classes, such as special columns, or meta information. JPOX is very unobtrusive as far as the datastore schema is concerned. It minimises the addition of any JDO artifacts to the datastore, and adds nothing (other than any datastore identities) to any schema tables. The only thing that JPOX does add to the schema is a single table that stores information about the classes being persisted (this is optional, and can be replaced by an XML file if required). JPOX can persist to a datastore that already contains a schema, or alternatively can create the datastore schema for you. It can exist alongside existing tables leaving them untouched. It is not necessary to have a database specifically for JPOX. When having JPOX generate the schema for you, it is advisable to run the JPOX SchemaTool before running your system. This can be used to ensure that the correct datastore schema is present, and ready for use.
![]() JPOX can generate the schema for the developer as it encounters classes in the persistence process. Alternatively you can use the SchemaTool application before starting your application. If you want to create the schema during the persistence process, the property org.jpox.autoCreateSchema provides a way of telling JPOX to do this. Thereafter, during calls to JPOX to persist classes or perform queries of persisted data, whenever it encounters a new class to persist that it has no information about, it will use the MetaData to check the datastore for presence of the table, and if it doesn't exist, will create it. In addition it will validate the correctness of the table (compared to the JDO Meta-Data for the class), and any foreign key constraints that it requires (to manage any relationships). If any foreign key constraints are missing it will create them. If you wanted to only create the tables required, and none of the constraints the property org.jpox.autoCreateTables provides this, simply performing the tables part of the above. If you want to create any missing columns that are required, the property org.jpox.autoCreateColumns provides this, validating and adding any missing columns. If you wanted to only create the constraints required, and none of the tables the property org.jpox.autoCreateConstraints provides this, simply performing the constraints part of the above.
![]() JPOX can check any existing schema against what is implied by the JDO Meta-Data. The property org.jpox.validateTables provides a way of telling JPOX to validate any tables that it needs against their current definition in the datastore. If the user already has a schema, and want to make sure that their tables match what JPOX requires (from the JDO Meta-Data definition) they would set this property to true. This can be useful for example where you are trying to map to an existing schema and want to verify that you've got the correct JDO Meta-Data definition. The property org.jpox.validateColumns provides a way of telling JPOX to validate any columns of the tables that it needs against their current definition in the datastore. If the user already has a schema, and want to make sure that their tables match what JPOX requires (from the JDO Meta-Data definition) they would set this property to true. This will validate the precise column types and widths etc, including defaultability/nullability settings. Please be aware that many JDBC drivers contain bugs that return incorrect column detail information and so having this turned off is sometimes the only option (dependent on the JDBC driver quality). The property org.jpox.validateConstraints provides a way of telling JPOX to validate any constraints (primary keys, foreign keys, indexes) that it needs against their current definition in the datastore. If the user already has a schema, and want to make sure that their table constraints match what JPOX requires (from the JDO Meta-Data definition) they would set this property to true.
![]() JPOX will, by default, use the default database schema for the Connection URL and user supplied. This may cause issues where the user has been set up and in some databases (e.g Oracle) you want to write to a different schema (which that user has access to). To achieve this in JPOX you would set the runtime properties javax.jdo.mapping.Catalog={the_catalog_name}
javax.jdo.mapping.Schema={the_schema_name}This will mean that all RDBMS DDL and SQL statements will prefix table names with the necessary catalog and schema names (specify which ones your datastore supports).
![]() There are occasions where the user has data in a datastore and they don't have write permission to that area. In this situation they do not want their persistence framework to try writing to the datastore since it will undoubtedly end in failure. JPOX caters for all of the 3 common situations.
JPOX provides an additional control over behaviour when using a read-only datastore. The default behaviour when the datastore is read-only and an object is attempted to be persisted is to throw an exception. You can change this using the PMF property org.jpox.readOnlyDatastoreAction with values of "EXCEPTION" (default), and "IGNORE". "IGNORE" has the effect of simply ignoring all attempted updates to readonly objects. This is available from JPOX 1.1.8. |