Grails - 使用 VARCHAR2 字段作为表标识符 - 外键关系失败
我与旧版 Oracle 数据库集成,该数据库使用指定的 VARCHAR2 值作为主键。我正在与这个现有表创建一对多关系。旧表称为“应用程序”(我可能不会更改),新表称为“项目”。许多项目可以分配给一个应用程序。
当 GORM 创建 Project 表时,它会为外键 application_id 创建一个 NUMBER 列,即使这是 Applications 表中的 VARCHAR2 字段。
class Application {
static hasMany = [projects : Project]; // does not fix problem
String application_id;
...
static mapping = {
table 'applications'
version false
id (column:'application_id')
}
static constraints = {
application_id(maxSize:16,blank:false,unique:true,type:"string",generator:"assigned")
}
...
}
class Project {
Application application;
...
}
当我编译应用程序时,我收到如下警告: 不成功:alter table项目添加约束FKED904B1956694CB5外键(application_id) ORA-02267: 列类型与引用的列类型不兼容
当我运行应用程序并单击应用程序控制器时,出现以下错误: SQL状态[99999];错误代码[17059];无法转换为内部表示; 无法转换为内部表示形式
嵌套异常是 java.sql.SQLException:当我单击“项目”| 时 创建我收到此错误: 无法转换为内部表示;嵌套异常是 java.sql.SQLException: 无法转换为 /project/create:172 处的内部表示
那么如何将 Project 类设置为期望应用程序有 VARCHAR2 外键?
感谢您的帮助!
I am integrated with a legacy Oracle database which uses assigned VARCHAR2 values for primary keys. I am creating a one-to-many relationship with this existing table. The legacy table is called Applications (which I may not alter) and the new table is called Projects. Many projects may be assigned to one application.
When GORM creates the Project table it is creating a NUMBER column for the foreign key, application_id, even though this is a VARCHAR2 field in the Applications table.
class Application {
static hasMany = [projects : Project]; // does not fix problem
String application_id;
...
static mapping = {
table 'applications'
version false
id (column:'application_id')
}
static constraints = {
application_id(maxSize:16,blank:false,unique:true,type:"string",generator:"assigned")
}
...
}
class Project {
Application application;
...
}
When I compile the app I get warnings like this:
Unsuccessful: alter table project add constraint FKED904B1956694CB5 foreign key (application_id)
ORA-02267: column type incompatible with referenced column type
When I run the app and click on Application controller I get this error:
SQL state [99999]; error code [17059]; Fail to convert to internal representation; nested exception is java.sql.SQLException: Fail to convert to internal representation
When I click on Project | create I get this error:
Fail to convert to internal representation; nested exception is java.sql.SQLException: Fail to convert to internal representation at /project/create:172
So how can I set the Project class to expect a VARCHAR2 foreign key for the Application?
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请查看这个网站。也许它会对你有所帮助。
Look at this site. Maybe it will help you.
这是应用程序类中的更正...以防其他人搜索此内容:
Here is the correction in the Application class... in case anyone else searches for this: