org.springframework.orm.jpa.JpaSystemException:org.hibernate.exception.SQLGrammarException:ERROR:column" ----"关系" -----"不存在

时间:2017-07-17 17:50:46

标签: postgresql hibernate persistence jpql

我在使用持久性API将对象存储到数据库时遇到此错误。对我来说,它看起来还不错。无法在模型类中的任何位置找到问题。

如果您需要任何其他信息,请与我们联系。

提前致谢。

错误:

  

SEVERE:servlet [Project]的Servlet.service()与路径的上下文   [/ Project]引发异常[请求处理失败;嵌套   异常是org.springframework.orm.jpa.JpaSystemException:   org.hibernate.exception.SQLGrammarException:错误:列   "如first_name"关系"用户"不存在位置:36;嵌套   异常是javax.persistence.PersistenceException:   org.hibernate.exception.SQLGrammarException:错误:列   "如first_name"关系"用户"不存在位置:36]   根本原因org.postgresql.util.PSQLException:错误:列   "如first_name"关系"用户"不存在位置:36 at   org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)     在   org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)   ......

User.java

public class User implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
private Long id;

@Column(unique = true, nullable = false)
private String email;

@Column(nullable = false)
private String password;

@Column(name = "first_name")
private String firstName;

@Column(name = "last_name")
private String lastName;

@Column( name = "phone" )
private String phone;

@OneToMany(targetEntity=Address.class, mappedBy="user",cascade=CascadeType.ALL)
private List<Address> address;

private boolean enabled;

public boolean isEnabled() {
    return enabled;
}

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

@ElementCollection
@CollectionTable(name = "authorities",
    joinColumns = @JoinColumn(name = "user_id" ) )
@Column( name = "role" )
private Set<String> roles;

@Transient
private String password2;

public User()
{
    roles = new HashSet<String>();
    enabled=true;
}

public boolean isAdmin()
{
    return roles.contains( "ROLE_ADMIN" );
}

public boolean isUser()
{
    return roles.contains( "ROLE_USER" );
}

public Long getId()
{
    return id;
}

public void setId( Long id )
{
    this.id = id;
}

public String getEmail()
{
    return email;
}

public void setEmail( String email )
{
    this.email = email;
}

public String getPassword()
{
    return password;
}

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

public String getFirstName()
{
    return firstName;
}

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

public String getLastName()
{
    return lastName;
}

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

public String getPhone()
{
    return phone;
}

public void setPhone( String phone )
{
    this.phone = phone;
}

public Set<String> getRoles()
{
    return roles;
}

public void setRoles( Set<String> roles )
{
    this.roles = roles;
}

public String getPassword2()
{
    return password2;
}

public void setPassword2( String password2 )
{
    this.password2 = password2;
}

}

数据库:

create table users (
        id int8 not null,
        email varchar(255) not null unique,
        enabled boolean not null,
        first_name varchar(255),
        last_name varchar(255),
        password varchar(255) not null,
        phone varchar(255),
        primary key (id)
    );

控制器:

@RequestMapping(value = "user/registration.html", method = RequestMethod.POST)
    public String registrationPOST(@ModelAttribute User user, ModelMap models, SessionStatus sessionStatus)
    {
        user.setEnabled(false);
        user = userDao.saveUser(user);
        sessionStatus.setComplete();
        models.put("status","Check your email to confirm your account");
        return "user/registration";
    }

0 个答案:

没有答案