我正在尝试从 DataNucleus SchemaTool 为 mysql 数据库生成架构,该数据库将存储国家/地区和州。以下是该代码的示例:
@PersistenceCapable
Public class State{
private String shortCode;
private String fullName;
@Column(allowsNull = "true",name="country_id")
private Country countryId;
}
以下是我的 schemaGeneration 属性:
datanucleus.ConnectionDriverName=com.mysql.jdbc.Driver
datanucleus.ConnectionURL=jdbc:mysql://localhost:3306/geog
datanucleus.ConnectionUserName=geog
datanucleus.ConnectionPassword=geogPass
datanucleus.schema.validateTables=true
datanucleus.mapping.Catalog=geog
datanucleus.mapping.Schema=geog
在我的 Country 类中,我也有一个来自 Collection 的映射,以便正确构建 States 到 Country 表的 FK 引用。
但是有一个问题。在生成的 SQL 脚本中,索引部分将架构名称作为索引名称本身的一部分,这会导致整个脚本失败。这是那篇文章:
CREATE INDEX `GEOG`.`MST_STATE_N49` ON `GEOG`.`MST_STATE` (`COUNTRY_ID`);
请注意索引名称的 GEOG
.MST_STATE_N49
部分中的架构名称。
我尝试将架构和目录名称设置为空白,但这会产生“”。MST_STATE_N49
,但仍然失败。
我在 Data nucle JDO 3.1 上使用 MySQL Server 5.7.17,并使用 5.1.42 版本的 JDBC 驱动程序(是的,不是最新的)
有关如何删除生成的 DDL 中的架构/目录名称的任何提示吗?
最佳答案
为什么在使用 MySQL 时要放置“datanucleus.mapping.Schema”?我上次查看时 MySQL 没有使用模式。同样,“datanucleus.mapping.Catalog”是由您的 URL 有效定义的! MySQL 实际上仅支持 JDBC 目录,映射到“数据库”,如下所示 post 。由于 DataNucleus 仅使用 JDBC 驱动程序,因此目录是唯一有用的输入。
因此,架构和目录属性的删除将默认到正确的位置。
关于mysql - 生成 datanucleus JDO 模式时创建索引语句中的模式名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44087380/