mysqlsql-serverjdodatanucleuspersistence-manager

JDO Class - convert to varchar or nvarchar based on MySQL or MSSQL


I have a JDO Class. Some of the attributes are as shown below:

@Column(jdbcType = "VARCHAR", length = 200)
String anotherSrcFieldValue;

@Column(jdbcType = "BIGINT")
long tgtFieldId;

@Column(jdbcType = "VARCHAR", length = 200)
String tgtFieldValue;

With MySQL and MSSQL it works fine.

My requirement is, if it is MySQL make it a column of type VARCHAR; and when it is MSSQL, create a column of type NVARCHAR. How can I achieve this?

A second requirement is one entity class to be run on both the databases.


Solution

  • All JDO docs I've seen explain clearly that putting schema specific info in annotations is a bad idea. Consequently you should have 2 files "package-mysql.orm" and "package-mssql.orm" to specify the schema-specific parts of the mapping, and set "datanucleus.Mapping" to be either "mysql" or "mssql" depending on your datastore. As per http://www.datanucleus.org/products/accessplatform_4_2/jdo/orm/metadata_orm.html