Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用persist()时出错_Java_Hibernate_Persistence_Spring Roo - Fatal编程技术网

Java 使用persist()时出错

Java 使用persist()时出错,java,hibernate,persistence,spring-roo,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.g

我有以下代码:

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=密码,rootBeanClass=类 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.commyfirstname mylastname设置firstname用户, nombre:User[firstName=,lastName=,emailAddress=,password=,activationDate=,activationKey=,enabled=,locked=,id=,version=,clients=,incidencias=,userRoles=,empresaId=]

我不知道为什么用户的所有参数都为空

这是我的用户\u Roo\u 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;
    }

}
//警告:不要编辑此文件。该文件由SpringRoo管理。
//如果希望编辑任何成员,可以将代码推入target.java编译单元。
包com.springsource.marshall.domain;
导入com.springsource.marshall.domain.Cliente;
导入com.springsource.marshall.domain.Empresa;
导入com.springsource.marshall.domain.Incidencia;
导入com.springsource.marshall.domain.User;
导入com.springsource.marshall.domain.UserRole;
导入java.util.Date;
导入java.util.Set;
导入javax.persistence.Column;
导入javax.persistence.JoinColumn;
导入javax.persistence.manytone;
导入javax.persistence.OneToMany;
导入javax.persistence.Temporal;
导入javax.persistence.TemporalType;
导入org.springframework.format.annotation.DateTimeFormat;
特权方面用户\u Roo\u DbManaged{
@OneToMany(mappedBy=“userId”)
私有设置User.clients;
@OneToMany(mappedBy=“userId”)
私有集User.incidencias;
@OneToMany(mappedBy=“userEntry”)
私有设置User.userRoles;
@许多酮
@JoinColumn(name=“empresa\u id”,referencedColumnName=“id”)
私有Empresa User.empresaId;
@列(name=“firstName”,长度=99,可插入=false,可更新=false)
私有字符串User.firstName;
@列(name=“lastName”,长度=30,可插入=false,可更新=false)
私有字符串User.lastName;
@列(name=“password”,长度=100,可插入=false,可更新=false)
私有字符串User.password;
@列(name=“emailAddress”,长度=45,可插入=false,可更新=false)
私有字符串User.emailAddress;
@列(name=“activationDate”,insertable=false,updateable=false)
@时态(TemporalType.DATE)
@日期时间格式(style=“M-”)
私有日期User.activationDate;
@列(name=“activationKey”,长度=45,可插入=false,可更新=false)
私有字符串User.activationKey;
@列(name=“enabled”,insertable=false,updateable=false)
私有布尔用户启用;
@列(name=“locked”,insertable=false,updateable=false)
私有布尔用户锁定;
public Set User.getClientes(){
回头客;
}
public void User.setclients(设置客户端){
this.clientes=客户;
}
公共集用户.getIncidencias(){
复发率;
}
public void User.setIncidencias(Set incidencias){
this.incidencias=incidencias;
}
public Set User.getUserRoles(){
返回用户角色;
}
public void User.setUserRoles(Set userRoles){
this.userRoles=userRoles;
}
public Empresa User.getEmpresaId(){
返回empresaId;
}
public void User.setEmpresaId(Empresa empresaId){
this.empresaId=empresaId;
}
公共字符串User.getFirstName(){
返回名字;
}
public void User.setFirstName(字符串firstName){
this.firstName=firstName;
}
公共字符串User.getLastName(){
返回姓氏;
}
public void User.setLastName(字符串lastName){
this.lastName=lastName;
}
公共字符串User.getPassword(){
返回密码;
}
public void User.setPassword(字符串密码){
this.password=密码;
}
公共字符串User.getEmailAddress(){
返回电子邮件地址;
}
public void User.setEmailAddress(字符串emailAddress){
this.emailAddress=电子邮件地址;
}
公共日期用户.getActivationDate(){
返回激活状态;
}
public void User.setActivationDate(日期activationDate){
this.activationDate=activationDate;
}
公共字符串User.getActivationKey(){
返回激活键;
}
public void User.setActivationKey(字符串activationKey){
this.activationKey=activationKey;
}
public Boolean User.getEnabled(){
返回启用;
}
public void User.setEnabled(已启用布尔值){
this.enabled=已启用;
}
public Boolean User.getLocked(){
返回锁定;
}
public void User.setLocked(布尔锁定){
this.locked=locked;
}
}
有人有什么可能的解决办法吗


谢谢

请为用户实体添加代码(仅属性和注释)。是否检查了“null”的请求参数?在调用persist()之前,请检查所有必需的值是否为非null?谢谢您的回答!!我已经编辑了我的帖子。