0
は、私はこのような3つのクラスが持つエラーながら
package mnm
class User {
String login
String password
static hasMany = [ holidays : Holiday ]
static constraints = {
}
}
HolidayStatus:
package mnm
class HolidayStatus {
String name
static belongsTo = [holiday :Holiday ]
static constraints = {
name(blank:false)
}
}
私はこのような統合テストを書いた:
void testWithBelongsTo() {
def user1 = new User(login:"anto", password:"secret")
assert user1.save()
def holiday1 = new Holiday(justification:"went to trip")
assert holiday1.save()
user1.addToHolidays(holiday1)
assertEquals 1, User.get(user1.id).holidays.size()
user1.delete()
assertFalse User.exists(user1.id)
assertFalse Holiday.exists(holiday1.id)
}
それはテストが合格している、完璧に動作します。そして、私はこのように私のHoliday
クラスを変更する場合:
class Holiday {
Date start
Date end
HolidayStatus status
String justification
static belongsTo = [ user : User ]
static constraints = {
status(nullable:true)
user(nullable:true)
start(nullable:true)
end(nullable:true)
}
}
(つまりDate
タイプのものであり、新たな分野、すなわちstart, end
を、追加しています。)私はこのような何かに私のテストを変更した場合今
:
could not insert: [mnm.Holiday]; SQL [insert into holiday (id, version, end, justification, start, status_id, user_id) values (null, ?, ?, ?, ?, ?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [mnm.Holiday]
org.springframework.dao.InvalidDataAccessResourceUsageException: could not insert: [mnm.Holiday]; SQL [insert into holiday (id, version, end, justification, start, status_id, user_id) values (null, ?, ?, ?, ?, ?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [mnm.Holiday]
at mnm.HolidayIntegrationTests.testWithBelongsTo(HolidayIntegrationTests.groovy:43)
Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [mnm.Holiday]
at $Proxy11.saveOrUpdate(Unknown Source)
at mnm.HolidayIntegrationTests.testWithBelongsTo(HolidayIntegrationTests.groovy:43)
at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:271)
at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:228)
at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:187)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:174)
at TestApp$_run_closure1.doCall(TestApp.groovy:82)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: java.sql.SQLException: Table not found in statement [insert into holiday (id, version, end, justification, start, status_id, user_id) values (null, ?, ?, ?, ?, ?, ?)]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
at $Proxy8.prepareStatement(Unknown Source)
:
void testWithBelongsTo() {
def user1 = new User(login:"anto", password:"secret")
assert user1.save()
def holiday1 = new Holiday(justification:"went to trip", start: new Date("05/01/2010"),end: new Date("05/01/2011"))
assert holiday1.save()
user1.addToHolidays(holiday1)
assertEquals 1, User.get(user1.id).holidays.size()
user1.delete()
assertFalse User.exists(user1.id)
assertFalse Holiday.exists(holiday1.id)
}
私はこのようなエラーを取得しています
ここで何が起こっていますか?私はどこでミスをしましたか?これは他のテストにも失敗する原因になります!
ありがとうございます。
あなたの正しい+1!ありがとう....... –