Grails 从 2.4.5 升级到 3.3.2:关系“xxx”不存在
Posted
技术标签:
【中文标题】Grails 从 2.4.5 升级到 3.3.2:关系“xxx”不存在【英文标题】:Grails upgrade from 2.4.5 to 3.3.2: Relation 'xxx' does not exist 【发布时间】:2018-02-23 13:10:53 【问题描述】:将 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)
关于问题所在的任何想法。提前致谢!
编辑: 部门标签:
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
类引导程序
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]
【问题讨论】:
发生这种情况的原因有很多。你能展示有问题的BootStrap
代码和相关的域类吗?
@JeffScottBrown 编辑了我的问题
【参考方案1】:
大概您同时从 Hibernate 4 更新到 5? Hibernate 5 目前存在生成外键不同的问题:https://hibernate.atlassian.net/browse/HHH-10574
我不确定这是您看到的问题,但可能与此有关。即使没有,也需要注意。
【讨论】:
【参考方案2】:问题在于表中的默认值。从 Grails 社区获得帮助,执行 grails schema-export,从空数据库开始并执行 ddl.sql.
【讨论】:
以上是关于Grails 从 2.4.5 升级到 3.3.2:关系“xxx”不存在的主要内容,如果未能解决你的问题,请参考以下文章
Grails,从 Acegi 升级到 Spring 安全插件