1
我有一個類,它擴展了另一個類的一些基本屬性。我正在使用CRUD存儲庫與我的MySql數據庫進行通信。我沒有得到在基類中定義的字段的值。CRUD存儲庫沒有返回超類數據
例如:我將createdBy和modifiedBy設置爲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;
}
任何幫助表示讚賞。
我的問題是不是特別審計領域。我沒有得到子類字段的值。在我的示例中,我沒有lastModified和createdAt。 – Rajagopal