使用persist()时出错

时间:2013-05-02 11:35:44

标签: java hibernate persistence spring-roo

我有这段代码:

user.setFirstName(requ.getParameter("nombre"));
user.setLastName(requ.getParameter("apellidos"));
user.setEmailAddress(requ.getParameter("email"));

user.persist();

我收到了这个错误:

  

类[com.springsource.marshall.domain.User]的验证失败   在群体的持续时间[javax.validation.groups.Default,]   违反约束的清单:[   ConstraintViolationImpl {interpolatedMessage ='no puede ser null',   propertyPath = emailAddress,rootBeanClass = class   com.springsource.marshall.domain.User,   messageTemplate = '{} javax.validation.constraints.NotNull.message'}   ConstraintViolationImpl {interpolatedMessage ='no puede ser null',   propertyPath = password,rootBeanClass = class   com.springsource.marshall.domain.User,   messageTemplate = '{} javax.validation.constraints.NotNull.message'}   ConstraintViolationImpl {interpolatedMessage ='no puede ser null',   propertyPath = firstName,rootBeanClass = class   com.springsource.marshall.domain.User,   messageTemplate ='{javax.validation.constraints.NotNull.message}'}]

我试过了:

User user = new User();

System.out.println(requ.getParameter("email"));
System.out.println(requ.getParameter("nombre"));
System.out.println(requ.getParameter("apellidos"));
user.setFirstName(requ.getParameter("nombre"));
user.setLastName(requ.getParameter("apellidos"));
user.setEmailAddress(requ.getParameter("email"));
user.setPassword("poruesadf");
System.out.println("User:" + user);
user.persist();

我得到了:

  

myemail@hotmail.com myfirstname mylastname set firstname User,   农布雷:用户[名字=,姓氏=,EMAILADDRESS =,密码=,activationDate =,激活密钥=,=使能,锁定=,ID =,版本=,clientes =,incidencias =,的UserRole =,empresaId =]

我不知道为什么User有所有参数null ...

这是我的 User_Roo_DbManaged.aj

// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).

package com.springsource.marshall.domain;

import com.springsource.marshall.domain.Cliente;
import com.springsource.marshall.domain.Empresa;
import com.springsource.marshall.domain.Incidencia;
import com.springsource.marshall.domain.User;
import com.springsource.marshall.domain.UserRole;
import java.util.Date;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.springframework.format.annotation.DateTimeFormat;

privileged aspect User_Roo_DbManaged {

    @OneToMany(mappedBy = "userId")
    private Set<Cliente> User.clientes;

    @OneToMany(mappedBy = "userId")
    private Set<Incidencia> User.incidencias;

    @OneToMany(mappedBy = "userEntry")
    private Set<UserRole> User.userRoles;

    @ManyToOne
    @JoinColumn(name = "empresa_id", referencedColumnName = "id")
    private Empresa User.empresaId;

    @Column(name = "firstName", length = 99, insertable=false,updatable=false)
    private String User.firstName;

    @Column(name = "lastName", length = 30, insertable=false,updatable=false)
    private String User.lastName;

    @Column(name = "password", length = 100, insertable=false,updatable=false)
    private String User.password;

    @Column(name = "emailAddress", length = 45, insertable=false,updatable=false)
    private String User.emailAddress;


    @Column(name = "activationDate", insertable=false,updatable=false)
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(style = "M-")
    private Date User.activationDate;

    @Column(name = "activationKey", length = 45, insertable=false,updatable=false)
    private String User.activationKey;

    @Column(name = "enabled", insertable=false,updatable=false)
    private Boolean User.enabled;

    @Column(name = "locked", insertable=false,updatable=false)
    private Boolean User.locked;

    public Set<Cliente> User.getClientes() {
        return clientes;
    }

    public void User.setClientes(Set<Cliente> clientes) {
        this.clientes = clientes;
    }

    public Set<Incidencia> User.getIncidencias() {
        return incidencias;
    }

    public void User.setIncidencias(Set<Incidencia> incidencias) {
        this.incidencias = incidencias;
    }

    public Set<UserRole> User.getUserRoles() {
        return userRoles;
    }

    public void User.setUserRoles(Set<UserRole> userRoles) {
        this.userRoles = userRoles;
    }

    public Empresa User.getEmpresaId() {
        return empresaId;
    }

    public void User.setEmpresaId(Empresa empresaId) {
        this.empresaId = empresaId;
    }

    public String User.getFirstName() {
        return firstName;
    }

    public void User.setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String User.getLastName() {
        return lastName;
    }

    public void User.setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String User.getPassword() {
        return password;
    }

    public void User.setPassword(String password) {
        this.password = password;
    }

    public String User.getEmailAddress() {
        return emailAddress;
    }

    public void User.setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public Date User.getActivationDate() {
        return activationDate;
    }

    public void User.setActivationDate(Date activationDate) {
        this.activationDate = activationDate;
    }

    public String User.getActivationKey() {
        return activationKey;
    }

    public void User.setActivationKey(String activationKey) {
        this.activationKey = activationKey;
    }

    public Boolean User.getEnabled() {
        return enabled;
    }

    public void User.setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Boolean User.getLocked() {
        return locked;
    }

    public void User.setLocked(Boolean locked) {
        this.locked = locked;
    }

}

有没有人有任何可能的解决方案?

谢谢!

0 个答案:

没有答案