问题
Hi i have this following Domain in Grails
class Customer {
static mapping = {
table 'customer'
// version is set to false, because this isn't available by default for legacy databases
version false
id column:'customerid' //generator:'identity',
}
Long customerid
Long customergroupid
String username
String password
String name
String street
String city
String province
String postcode
String country
Date dateregistered
String balance
Long parentid
String parentrebate
String metapath
Long metalevel
Integer smsreplystatus
Integer status
String reversalurl
static constraints = {
customerid(insert:false,update:false)
customergroupid(max: 9999999999L)
username(size: 1..20, blank: false)
password(size: 1..32, blank: false)
name(size: 1..20, blank: false)
street(size: 0..50)
city(size: 0..20)
province(size: 0..20)
postcode(size: 0..5)
country(size: 0..20)
dateregistered(nullable: true)
balance()
parentid(max: 9999999999L)
parentrebate()
metapath(size: 1..255, blank: false)
metalevel(max: 9999999999L)
smsreplystatus(max: 99999)
status(max: 99999)
reversalurl(size: 0..50)
}
String toString() {
return "${customerid}"
}
}
i have current database with existing data, and has mapping to GORM with GRAG but i'm getting this error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: postgresql.Customer column: customerid (should be mapped with insert="false" update="false")
... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: postgresql.Customer column: customerid (should be mapped with insert="false" update="false")
回答1:
Had same problem, remove "Long customerid"
This may not be a workable solution but at least the app compiles and creates the table.
Have not investigated at all as I just managed to get this working -- perhaps when setting a custom identity column, the property definition is implied (thus the "repeated column..." error)
来源:https://stackoverflow.com/questions/4457727/how-to-solve-grails-error-repeated-column-in-mapping-for-entity-on-existing-pos