我正在尝试映射此类的列名称:
class Amount{
String total //Total amount of something
String type //Type of amount, Dollars, %, Times something
Bonification bonificationRate //the amount can be "x times another bonification"
static belongsTo = [parentBonification: Bonification]
static mapping = {
table "AMOUNTS"
total column: "AMOU_TTOTAL"
type column: "AMOU_TTYPE"
parentBonification column: "BONI_CID"
bonificationRate column: "BONI_TRATE_CID"
}
}
class Bonification {
//among other things:
Amount amount
}
事情不是在数据库中创建
Bonification
类的任何字段,不要使用我给他们的名称,也不要使用默认的默认名称。
评论编辑:
dbCreate = "update"
上dbCreate = "create-drop"
,因为有些数据目前无法删除。 dbCreate = create-drop
安装了新的本地Derby数据库。仍然没有运气。 (PD:将保留所有其他字段并使用正确的列名进行映射,只有这两个
Bonification
字段才是问题)还有另一种方法吗?
编辑询问的DataSource.groovy
(从Config.groovy访问的外部文件
grails.config.locations = [ "file:${extConfig}/${appName}Config.groovy"]
)package xx.xxx.xxxx.xxxXxxx
dataSource
{
pooled = true
dialect = "org.hibernate.dialect.Oracle10gDialect"
driverClassName = "oracle.jdbc.OracleDriver"
username = "XXX"
password = "XXX"
properties {
maxActive = 100
maxIdle = 25
minIdle = 5
initialSize = 5
minEvictableIdleTimeMillis = 60000
timeBetweenEvictionRunsMillis = 60000
maxWait = 10000
validationQuery = "select 1 from dual"
}
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
development {
println "Including external DataSource"
dataSource {
dbCreate = "update"
url = "jdbc:oracle:thin:@xxx.xxx.xx:xxxx:XXXX"
}
}
}
最佳答案
好吧,终于我明白了。
我使用了“mappedBy”属性。
http://grails.org/doc/2.1.0/ref/Domain%20Classes/mappedBy.html
该文档(6.2.1.2 One-to-many)表示该文件用于“hasMany”端。这让我感到困惑,因为我在Class Amount
中没有hasMany,而是两个相同类型的字段。
我真正需要做的是使用mapledBy属性,而不是在Amount类中,而是在Bonification类中使用,该类仅对Amount
进行引用。
然后,我将Bonification告诉Amount Class
,他必须支持引用,以便“他”不会感到困惑,并将bonificationRate
字段用作字段,而不是像我以前认为的那样作为引用。
class Amount{
String total //Total amount of something
String type //Type of amount, Dollars, %, Times something
Bonification bonificationRate //the amount can be "x times another bonification"
static belongsTo = [parentBonification: Bonification]
static mapping = {
table "AMOUNTS"
total column: "AMOU_TTOTAL"
type column: "AMOU_TTYPE"
parentBonification column: "BONI_CID"
bonificationRate column: "BONI_TRATE_CID"
}
}
class Bonification {
//among other things:
Amount amount
static mappedBy = [amount: "parentBonification"]
}
那没有创建
parentBonification "BONI_CID" column
,但确实创建了我需要的bonificationRate "BONI_TRATE_CID"
。对不起,如果太乱了。谢谢您的宝贵时间,无论如何都需要帮助。