【发布时间】:2016-03-29 18:05:30
【问题描述】:
我有几个具有多对一关系的 mysql 表,它们使用映射表来建立关系。如下
book_type_map
Column Datatype
book_id Char(36)
book_type_id Char(36)
book_type
Column Datatype
book_type_id Char(36)
book_type Text
default TinyInt(1)
books
Column Datatype
book_id Char(36)
如您所见,book 表或book_type 表没有相互引用的列,我需要能够从book 访问book_type。这些是Book 和BookType 的域对象
class Book {
String id
BookType bookType
static mapping = {
table 'books'
id column: 'book_id', generator: 'uuid2'
bookType joinTable: [ name: 'book_type_map',
key: 'book_id',
column: 'book_type_id']
}
}
class BookType {
String id
String type
Boolean default
static mapping = {
table 'book_type'
id column: 'book_type_id', generator: 'uuid2'
type column: 'book_type'
}
}
当我运行它时,当我执行 Book.findAll() 时会出现此异常
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:“字段列表”中的未知列“this_.book_type_id”
我认为我的映射不正确。如果有人能指出我正确的方向,我将不胜感激。
【问题讨论】:
-
表 'books' 与您上面列出的表结构不匹配。我认为这是一个错字?
-
这是一个错字@ErikAhlswede。
标签: mysql grails grails-orm many-to-one