new user
26/06/2013 18:00
0
olá eu estou tentando aprender groovy, então me perdõem se falo alguma besteira.

eu nao consigo rodar um integration test com uma clases user.
A clase user:

class User {
String userId
String password
String homepage
Date dateCreated
Profile profile
Location location
static constraints = {
userId (blank:false, size:3..20, unique:true)
password (size:6..20, blank:false,
validator:{ passw, user ->
return passw != user.userId
//return ( (passw ~= /[a-z]/ ) && (passw ~= /[A-Z]/) && (passw ~= /[1..9]/))
}
)
homepage (url:true, nullable:true)
profile (nullable:true, unique:true)
location (nullable:true)
dateCreated()
}
static mapping = {
profile (lazy:false)
location (lazy:false)
}
static hasMany = [posts: Post, tags: Tag, followedLocations: Location]
String toString(){
"${userId}"
}
}

o integration test é:
void testUserSave(){
def coord4 = new Coordinates(longitude:123.5, latitude:654.333)
def gps1 = new GeoPosition(coords:coord4)
def address1 = new Address(street:"Candelaria", number:6, postalCode:23000)
def location1 = new Location(address:address1, geoPosition:gps1)
def user = new User(userId:'israel', password:'israelariel', homepage:'http://www.if.usp.br', location:location1)
assertNotNull user.save()
assertNotNull user.id
}

dá o error:

could not insert: [com.project.User]; SQL [insert into user (id, version, date_created, homepage, location_id, password, profile_id, user_id) values (null, ?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.project.User]
org.springframework.dao.DataIntegrityViolationException: could not insert: [com.project.User]; SQL [insert into user (id, version, date_created, homepage, location_id, password, profile_id, user_id) values (null, ?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.project.User]
at com.project.UserIntegrationTests.testUserSave(UserIntegrationTests.groovy:26)
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [com.project.User]
Caused by: org.h2.jdbc.JdbcSQLException: NULL not allowed for column "LOCAL_ID"; SQL statement:
insert into user (id, version, date_created, homepage, location_id, password, profile_id, user_id) values (null, ?, ?, ?, ?, ?, ?, ?) [23502-164]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.table.Column.validateConvertUpdateSequence(Column.java:293)
at org.h2.table.Table.validateConvertUpdateSequence(Table.java:680)
at org.h2.command.dml.Insert.insertRows(Insert.java:120)
at org.h2.command.dml.Insert.update(Insert.java:84)
at org.h2.command.CommandContainer.update(CommandContainer.java:73)
at org.h2.command.Command.executeUpdate(Command.java:226)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:143)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:129)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
System error
2013-06-26 14:46:01,757 [main] ERROR util.JDBCExceptionReporter - NULL not allowed for column "LOCAL_ID"; SQL statement:
insert into user (id, version, date_created, homepage, location_id, password, profile_id, user_id) values (null, ?, ?, ?, ?, ?, ?, ?) [23502-164]


ALGUMA IDEA?
Tags: integration test error save database


0
org.h2.jdbc.JdbcSQLException: NULL not allowed for column "LOCAL_ID"

Você não passou esse valor para a tabela. Ele não está mapeado no seu domain. Para mapear o nome da coluna, veja: http://grails.org/doc/latest/guide/GORM.html#tableAndColumnNames.

Se for a primary key da sua tabela, você não setou o auto increment.
27/06/2013 13:26



Ainda não faz parte da comunidade???

Para se registrar, clique aqui.


Aprenda Groovy e Grails com a Formação itexto!

Newsletter Semana Groovy

Assinar

Envie seu link!


Livro de Grails


/dev/All

Os melhores blogs de TI (e em português) em um único lugar!

 
Creative Commons
RSS Grails Brasil é mantido por itexto Consultoria.
Em caso de problemas contacte Henrique Lobo Weissmann (Kico) por e-mail: kico@itexto.com.br
Todo o conteúdo presente neste site adota o Creative Commons como licença padrão.
Ver: 4.14.0
itexto