Grails从2.4.5升级到3.3.2:关系'xxx'不存在
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Grails从2.4.5升级到3.3.2:关系'xxx'不存在相关的知识,希望对你有一定的参考价值。
是否需要进行数据库迁移以将Grails 2.4.5升级到3.3.2项目。目前,我在Bootstrap.groovy面临一个问题,应用程序无法启动。
ERROR: Relation "department" does not exist
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute statement; bad SQL grammar [n/a]; nested exception is org.postgresql.util.PSQLException: ERROR: relation "department" does not exist
Position: 13
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.grails.orm.hibernate.GrailsHibernateTemplate.convertJdbcAccessException(GrailsHibernateTemplate.java:731)
at org.grails.orm.hibernate.GrailsHibernateTemplate.convertHibernateAccessException(GrailsHibernateTemplate.java:719)
at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:303)
at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:243)
at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:117)
at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.performSave(AbstractHibernateGormInstanceApi.groovy:242)
at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.save(AbstractHibernateGormInstanceApi.groovy:159)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:151)
at org.grails.datastore.gorm.GormEntity$Trait$Helper$save.call(Unknown Source)
at vaparigrails.Company.save(Company.groovy)
at vaparigrails.Company.save(Company.groovy)
关于问题是什么的任何想法。提前致谢!
编辑:DepartmentTag:
class DepartmentTag {
String name
String details
static constraints = {
}
static belongsTo = [department : Department]
}
部门域类:
class Department {
String name
String address
String postalCode=''
String phoneNumber=''
String email=''
String homeCounty=''
Float latitude
Float longitude
List speciality
static constraints = {
homeCounty defaultValue: 'XXX'
email nullable:true, defaultValue: ''
phoneNumber nullable:true
address nullable:true
postalCode nullable:true
homeCounty nullable:true
latitude nullable:true, scale:6
longitude nullable:true, scale:6
speciality nullable: true
}
static mapping = {
vacancy lazy: false
}
static belongsTo = [company: Company]
static hasMany = [ speciality: String, tags : DepartmentTag, comments:Comment, phoneContacts:PhoneContact, ipAddresses: IPAddress]
static hasOne = [ vacancy : Vacancy ]
BootStrap.groovy中
class BootStrap {
def init = { servletContext ->
// Check whether the test data already exists.
def openTag = new DepartmentTag(name:"name1", details:"details1").save(failOnError:true)
def terTag = new DepartmentTag(name:"name2", details:"details2").save(failOnError:true)
}
if(!Company.count()) {
new Company(name: "company1", phoneNumber: "+12345", address: "address1", postalCode: "12345", email: "testi@testi.com", homeCounty: "XXX").save(failOnError: true)
.addToDepartment(new Department(name: "department_name", speciality: ["speciality1", "speciality2"], address: "address1", postalCode: "12345", homeCounty: "XXX", phoneNumber: "12345", email: "testi@testi.com", vacancy: new Vacancy(maleVacancy: 4, femaleVacancy: 4, specialVacancy: 2)).addToTags(terTag)).save(failOnError: true)
公司域类:
class Company {
String name
String phoneNumber=''
String address
String postalCode=''
String email=''
String homeCounty=''
static constraints = {
email nullable:true, defaultValue: ''
phoneNumber nullable:true
address nullable:true
postalCode nullable:true
homeCounty nullable:true
}
static hasMany = [department: Department,users : WebUser]
}
答案
想必你同时从Hibernate 4更新到5? Hibernate 5目前有一个问题,它以不同的方式生成外键:https://hibernate.atlassian.net/browse/HHH-10574
我不确定这是你看到的问题,但它可能是相关的。即使不是,也要注意这一点。
另一答案
问题是由于表中的默认值。得到Grails社区的帮助,执行grails schema-export,以空数据库启动并执行ddl.sql.
以上是关于Grails从2.4.5升级到3.3.2:关系'xxx'不存在的主要内容,如果未能解决你的问题,请参考以下文章
Grails,从 Acegi 升级到 Spring 安全插件