Десериализовать исключение в спящем режиме весной с OneToOne Mapping

0

Я использую Spring boot 2.1.2 с hibernate, и у меня есть два простых класса моделей, таких как учетная запись пользователя и пользователя, и эти две модели связаны с отображением oneToOne. Когда мы звоним пользователю, мне нужно также получить учетную запись пользователя. Я просто сопоставил модель учетной записи пользователя с моделью пользователя с помощью сопоставления oneToOne. Но когда я звоню, пользователь сталкивается с одним исключением десериализации.

Модель пользователя

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;


@Entity
@Table(name = "tbl_user")
public class User implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Integer id;

    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_account_id")
    UserAccount userAccount; 

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


    @Column(name = "active",nullable = false)
    private Integer active;

    @Column(name = "created_date",nullable = false)
    private Calendar createdDate;

    @Column(name = "created_by",nullable = false)
    private Integer created_by;

    @Column(name = "updated_date")
    private Calendar updatedDate;

    @Column(name = "updated_by")
    private Integer updated_by;



    public User() {
        super();
        // TODO Auto-generated constructor stub
    }

    public User(Integer id, UserAccount userAccount, String firstName, Integer active, Calendar createdDate,
            Integer created_by, Calendar updatedDate, Integer updated_by) {
        super();
        this.id = id;
        this.userAccount = userAccount;
        this.firstName = firstName;
        this.active = active;
        this.createdDate = createdDate;
        this.created_by = created_by;
        this.updatedDate = updatedDate;
        this.updated_by = updated_by;
    }



    public Integer getId() {
        return id;
    }

    public UserAccount getUserAccount() {
        return userAccount;
    }



    public void setUserAccount(UserAccount userAccount) {
        this.userAccount = userAccount;
    }


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

    public String getFirstName() {
        return firstName;
    }

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


    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }

    public Calendar getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Calendar createdDate) {
        this.createdDate = createdDate;
    }

    public Integer getCreated_by() {
        return created_by;
    }

    public void setCreated_by(Integer created_by) {
        this.created_by = created_by;
    }

    public Calendar getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Calendar updatedDate) {
        this.updatedDate = updatedDate;
    }

    public Integer getUpdated_by() {
        return updated_by;
    }

    public void setUpdated_by(Integer updated_by) {
        this.updated_by = updated_by;
    }


}

Модель учетной записи пользователя

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
@Table(name = "tbl_user_account")
public class UserAccount implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Integer id;

    @Column(name = "usere_name",nullable = false)
    UserAccount usereName;

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

    @Column(name = "active",nullable = false)
    private Integer active;

    @Column(name = "created_date",nullable = false)
    private Calendar createdDate;

    @Column(name = "created_by",nullable = false)
    private Integer created_by;

    @Column(name = "updated_date")
    private Calendar updatedDate;

    @Column(name = "updated_by")
    private Integer updated_by;



    public UserAccount(Integer id, UserAccount usereName, String password,Integer active,
            Calendar createdDate, Integer created_by, Calendar updatedDate, Integer updated_by) {
        super();
        this.id = id;
        this.usereName = usereName;
        this.password = password;
        this.active = active;
        this.createdDate = createdDate;
        this.created_by = created_by;
        this.updatedDate = updatedDate;
        this.updated_by = updated_by;
    }

    public UserAccount() {
        super();
        // TODO Auto-generated constructor stub
    }

    public Integer getId() {
        return id;
    }

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

    public UserAccount getUsereName() {
        return usereName;
    }

    public void setUsereName(UserAccount usereName) {
        this.usereName = usereName;
    }

    public String getPassword() {
        return password;
    }

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


    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }

    public Calendar getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Calendar createdDate) {
        this.createdDate = createdDate;
    }

    public Integer getCreated_by() {
        return created_by;
    }

    public void setCreated_by(Integer created_by) {
        this.created_by = created_by;
    }

    public Calendar getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Calendar updatedDate) {
        this.updatedDate = updatedDate;
    }

    public Integer getUpdated_by() {
        return updated_by;
    }

    public void setUpdated_by(Integer updated_by) {
        this.updated_by = updated_by;
    }


}

Файл свойств

# Application running port
server.port=8000

# Application running port
server.servlet.contextPath=/app

# Log files
logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR

#DB config
spring.datasource.url=jdbc:mysql://localhost:3306/db_name
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
Теги:
spring-boot
hibernate
one-to-one

1 ответ

1

Кажется, проблема в классе UserAccount, где вы определили поле UserAccount как тип UserAccount.

Я думаю, что это должна быть String.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню