[英]Grails domain without primary key
Anybody knows how to map grails domain class to MSSQL entity witch has not primary key 任何人都知道如何将grails域类映射到MSSQL实体,而主键却没有
class BRCategoryInt {
String lang
String name
static hasMany = [category: BRCategory]
static constraints = {
}
static mapping = {
table "brCategoryInt"
version false
//id column: ""
category column: "CategoryId"
lang column: "Lang"
name column: "Name"
}
}
In legacy database we have not primary key, just have an one FK CategoryId. 在旧版数据库中,我们没有主键,只有一个FK CategoryId。 Any help will be very appreciated. 任何帮助将不胜感激。
You should really always have a primary key on your data and I would recommend adding one just to keep everyone happy. 实际上,您应该始终在数据上拥有一个主键,我建议您添加一个主键只是为了让所有人满意。 If you cannot simply add a auto-increment id to your table you could use a composite key. 如果您不能简单地向表中添加自动递增ID,则可以使用复合键。 See documentation here . 请参阅此处的文档。 If you cannot do this either then I would consider re-thinking how youe data is laid out. 如果您也无法做到这一点,那么我将考虑重新考虑您的数据布局。
You cannot map such domain in Grails. 您无法在Grails中映射此类域。 To read/write such legacy tables try groovy Sql . 要读取/写入此类旧表,请尝试使用groovy Sql 。
It is my understanding that in theory it is possible to map to a table without a primary key, however I have yet to see it actually done. 据我了解,从理论上讲,可以在没有主键的情况下映射到表,但是我还没有看到它确实完成。 I have struggled with attempting it for days with nothing to show. 我努力尝试了好几天都没什么可显示的。
Short answer: Not possible in the current version of Grails. 简短答案:在当前版本的Grails中不可能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.