usuário informando o ID
18/09/2009 00:00
CREATE TABLE dbo.alunos
(
id NUMERIC (19) NOT NULL UNIQUE,
nome VARCHAR (255) NOT NULL,
)
class Alunos {
int id
String nome
static mapping = {
id generator:'assigned', column:'id'
version false
}
static constraints = {
id(size:3..10, blank:false, unique:true)
nome(size:5..50, blank:false, unique:true)
}
}
def save = {
def alunosInstance = new Alunos(params)
alunosInstance.id = Integer.parseInt(params.id)
<tr class="prop">
<td valign="top" class="name">
<label for="id">id:</label>
</td>
<td valign="top" class="value ${hasErrors(bean:alunosInstance,field:'id','errors')}">
<input type="text" id="id" name="id" value="${fieldValue(bean:alunosInstance,field:'id')}"/>
</td>
</tr>
CREATE TABLE dbo.alunos
(
id_aluno INTEGER NOT NULL,
nome VARCHAR (255) NOT NULL,
PRIMARY KEY (id_aluno)
)
GO
class Alunos {
Integer id_aluno
String nome
static mapping = {
table "alunos"
id name:"id_aluno", generator:"assigned"
version false
}
static constraints = {
id_aluno(blank:false, unique:true)
nome(size:5..50, blank:false, unique:true)
}
}
org.codehaus.groovy.runtime.InvokerInvocationException: org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type for class Alunos. Expected: class java.lang.Integer, got class java.lang.Long; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type for class Alunos. Expected: class java.lang.Integer, got class java.lang.Long
org.codehaus.groovy.runtime.InvokerInvocationException: org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type for class Alunos. Expected: class java.lang.Integer, got class java.lang.Long; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type for class Alunos. Expected: class java.lang.Integer, got class java.lang.Long
Dica: o Groovy Console é seu amigo. Experimente nele para ver o que acontece.
Para se registrar, clique aqui.