反序列化异常与OneToOne映射弹簧休眠

问题描述 投票:0回答:1

我使用Spring 2.1.2启动与Hibernate,和我有一样的用户和用户帐户简单的两模型类,而这些2种型号与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;
    }


}

UserAccount型号

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
java mysql hibernate spring-boot one-to-one
1个回答
1
投票

这个问题似乎是在UserAccount类,在这里你定义usereName字段UserAccount类型。

我想这应该是一个String

© www.soinside.com 2019 - 2024. All rights reserved.