3.5.4.3. MySQLDictionary Properties

The mysql dictionary also understands the following properties:

  • DateFractionDigits: Since MySQL 5.8 a timestamp (DATETIME) can store up to 6 sub-second fractions. The default in MySQL and OpenJPA is 0 for backward compatibility reasons. This default can be changed by setting DateFractionDigits to the number of sub-second fraction digits to be stored. This will e.g. result in a DATETIME(6) column. The number of fraction digits to be generated can also be tweaked via the @Column(scale=n) annotation, where n is the number of digits. This setting has primarily an impact on the generated SQL.

  • DriverDeserializesBlobs: Many older MySQL drivers automatically deserialize BLOBs on calls to ResultSet.getObject. The MySQLDictionary overrides the standard DBDictionary.getBlobObject method to take this into account. Defaults to true if driver version is less than 5.0, false otherwise. If your driver deserializes automatically, you may want to set this property to true.

  • TableType: The MySQL table type to use when creating tables. Defaults to "innodb".

  • UseClobs: Some older versions of MySQL do not handle CLOBs correctly. To disable CLOB functionality, set this to false. Defaults to true.

  • OptimizeMultiTableDeletes: MySQL as of version 4.0.0 supports multiple tables in DELETE statements. When this option is set, OpenJPA will use that syntax when doing bulk deletes from multiple tables. This can happen when the deleteTableContentsSchemaTool action is used. (See Schema Tool for more info about deleteTableContents.) Defaults to false, since the statement may fail if using InnoDB tables and delete constraints.

MySQL Connector/J supports replication connections that automatically send queries to a read/write source, or to a load balanced set of replicas, based on the read-only status of the connection. See MySQL Reference for more details.

This replication feature can be used transparently with OpenJPA application by following configuration:

  • Connector/J 8 and later: openjpa.ConnectionURL: jdbc:mysql:replication://source,replica/database with the regular driver com.mysql.cj.jdbc.Driver. A replication connection obtained from a DataSource or a connection pool is recognized as well.

  • Connector/J 5: openjpa.ConnectionDriverName: com.mysql.jdbc.ReplicationDriver and openjpa.ConnectionFactoryProperties: autoReconnect=true,roundRobinLoadBalance=true

The same holds for MariaDB Connector/J with a jdbc:mariadb:replication://primary,replica/database URL and the MariaDBDictionary.

OpenJPA keeps the connection of an EntityManager read-only outside of a transaction, so that those reads go to a replica, and makes it writable when a transaction begins, so that the statements of the transaction, its reads included, go to the source. The connections OpenJPA uses for sequences and for schema changes are never made read-only.