lundi 19 décembre 2016

Unknown column 'userentity0_.last_name' in 'field list'

i'm on a java web project working with framework spring but have a problem when working with database (inscription, connexion)

Here is my database Sql code:

Create table USER(
Login varchar(20) NOT NULL,
Password varchar(32) NOT NULL,
LastName varchar(20) NOT NULL,
Address varchar(60) NOT NULL,
Email varchar(50) NOT NULL,
MobilePhoneNumber int(10) NOT NULL,
LoyaltyPoints int(4) NOT NULL,
PhoneNumber int(9),
PRIMARY KEY (Login)
)

Here is my java model class:

package com.spring.henallux.model;

import java.sql.Date;
import java.util.GregorianCalendar;

public class User {

private String login;

private String password;

private String lastName;

private String address;

private String email;

private int mobilePhoneNumber;

private int loyaltyPoints;

private int phoneNumber;

public String getLogin() {
    return login;
}

public void setLogin(String login) {
    this.login = login;
}

public String getPassword() {
    return password;
}

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

public String getLastName() {
    return lastName;
}

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

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public String getEmail() {
    return email;
}

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

public int getMobilePhoneNumber() {
    return mobilePhoneNumber;
}

public void setMobilePhoneNumber(int mobilePhoneNumber) {
    this.mobilePhoneNumber = mobilePhoneNumber;
}

public int getLoyaltyPoints() {
    return loyaltyPoints;
}

public void setLoyaltyPoints(int loyaltyPoints) {
    this.loyaltyPoints = loyaltyPoints;
}

public int getPhoneNumber() {
    return phoneNumber;
}

public void setPhoneNumber(int phoneNumber) {
    this.phoneNumber = phoneNumber;
}

public User(){
    this.login = new String();
    this.password = new String();
    this.lastName = new String();
    this.address = new String();
    this.email = new String();
    this.mobilePhoneNumber = 0;
    this.loyaltyPoints = 0;
}
}

Here is my Entity class:

package com.spring.henallux.dataAccess.entity;

import javax.persistence.*;

@Entity
@Table(name="user")
public class UserEntity {

@Id
@Column(name="Login")
private String login;

@Column(name="Password", nullable=false)
private String password;

@Column(name="LastName", nullable=false)
private String lastName;

@Column(name="Address", nullable=false)
private String address;

@Column(name="Email", nullable=false)
private String email;

@Column(name="MobilePhoneNumber", nullable=false)
private int mobilePhoneNumber;

@Column(name="LoyaltyPoints", nullable=false)
private int loyaltyPoints;

@Column(name="PhoneNumber", nullable=true)
private int phoneNumber;

public String getLogin() {
    return login;
}

public void setLogin(String login) {
    this.login = login;
}

public String getPassword() {
    return password;
}

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

public String getLastName() {
    return lastName;
}

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

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public String getEmail() {
    return email;
}

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

public int getMobilePhoneNumber() {
    return mobilePhoneNumber;
}

public void setMobilePhoneNumber(int mobilePhoneNumber) {
    this.mobilePhoneNumber = mobilePhoneNumber;
}

public int getLoyaltyPoints() {
    return loyaltyPoints;
}

public void setLoyaltyPoints(int loyaltyPoints) {
    this.loyaltyPoints = loyaltyPoints;
}

public int getPhoneNumber() {
    return phoneNumber;
}

public void setPhoneNumber(int phoneNumber) {
    this.phoneNumber = phoneNumber;
}

/*@OneToOne(mappedBy="user", fetch=FetchType.LAZY)
private CommandEntity command;*/
}

And here is the error message :

2016-12-19 11:40:35.223 ERROR 7952 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : Unknown column 'userentity0_.last_name' in 'field list'
2016-12-19 11:40:35.225  INFO 7952 --- [nio-8080-exec-2] o.h.e.internal.DefaultLoadEventListener  : HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2016-12-19 11:40:35.249 ERROR 7952 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/dreamsport] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
...

And this message come when i try this:

public User save(User user){
    UserEntity userEntity = converter.userModelToUserEntity(user);
    userEntity = userRepository.save(userEntity);
    return converter.userEntityToUserModel(userEntity);
}




Aucun commentaire:

Enregistrer un commentaire