CRUD存储库未返回超类数据

时间:2016-11-10 17:04:36

标签: mysql spring-boot repository crud

我有一个类,它扩展了另一个类的一些基本属性。我正在使用CRUD存储库与MySql数据库进行通信。我没有得到基类中定义的字段的值。

例如:我正在创建并且修改为null。

实体类

@JsonInclude(JsonInclude.Include.NON_NULL)
@Entity
@Table(name = "user")
class User extends BaseEntity {

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

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

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

 /**
  * @return the id
  */
 public String getId() {
  return id;
 }

 /**
  * @param id the id to set
  */
 public void setId(String id) {
  this.id = id;
 }

 /**
  * @return the firstName
  */
 public String getFirstName() {
  return firstName;
 }

 /**
  * @param firstName the firstName to set
  */
 public void setFirstName(String firstName) {
  this.firstName = firstName;
 }

 /**
  * @return the lastName
  */
 public String getLastName() {
  return lastName;
 }

 /**
  * @param lastName the lastName to set
  */
 public void setLastName(String lastName) {
  this.lastName = lastName;
 }
}

基类

class BaseEntity {

 @JsonProperty("createdBy")
 @Column(name = "created_by")
 public String createdBy;

 @JsonProperty("modifiedBy")
 @Column(name = "modified_by")
 public String modifiedBy;

 /**
  * @return the createdBy
  */
 public String getCreatedBy() {
  return createdBy;
 }

 /**
  * @param createdBy the createdBy to set
  */
 public void setCreatedBy(String createdBy) {
  this.createdBy = createdBy;
 }

 /**
  * @return the modifiedBy
  */
 public String getModifiedBy() {
  return modifiedBy;
 }

 /**
  * @param modifiedBy the modifiedBy to set
  */
 public void setModifiedBy(String modifiedBy) {
  this.modifiedBy = modifiedBy;
 }
}

存储库

@Transactional
public interface UserRepo extends CrudRepository < User, String > {}

服务实施方法

public User getUser(String userId) {
    User user = gUnifyUserRepository.findOne(userId); 
    //Here the data for createdBy and modifiedBy is returned as null though i have value in DB
    return response;
}

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

public class BaseEntity implements Serializable {

    @LastModifiedDate
    private Date lastModified;
    @CreatedDate
    private Date createdAt;

使用上面的代码,让我知道

相关问题