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 settingDateFractionDigitsto the number of sub-second fraction digits to be stored. This will e.g. result in aDATETIME(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 toResultSet.getObject. TheMySQLDictionaryoverrides the standardDBDictionary.getBlobObjectmethod to take this into account. Defaults totrueif driver version is less than 5.0,falseotherwise. If your driver deserializes automatically, you may want to set this property totrue. -
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 tofalse. Defaults totrue. -
OptimizeMultiTableDeletes: MySQL as of version 4.0.0 supports multiple tables inDELETEstatements. When this option is set, OpenJPA will use that syntax when doing bulk deletes from multiple tables. This can happen when thedeleteTableContentsSchemaToolaction is used. (See Schema Tool for more info aboutdeleteTableContents.) Defaults tofalse, 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/databasewith the regular drivercom.mysql.cj.jdbc.Driver. A replication connection obtained from aDataSourceor a connection pool is recognized as well. -
Connector/J 5:
openjpa.ConnectionDriverName: com.mysql.jdbc.ReplicationDriverandopenjpa.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.