是否需要进行数据库迁移以将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]
}
答案 0 :(得分:0)
大概是你同时从Hibernate 4更新到5? Hibernate 5目前存在以不同方式生成外键的问题:https://hibernate.atlassian.net/browse/HHH-10574
我不确定这是您所看到的问题,但可能与此有关。即使不是,也要注意一些事情。
答案 1 :(得分:0)