懒惰@LastModifiedBy

时间:2016-06-18 23:12:16

标签: spring hibernate

如何使用@LastModifiedBy注释延迟加载多对一列?

例如,我创建了ByBy和lastModifiedBy列:

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "manager_id")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIdentityReference(alwaysAsId = true)
private User manager;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@CreatedBy
@JoinColumn(name = "created_by")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIdentityReference(alwaysAsId = true)
@JsonProperty("created_user_id")
private User createdBy;

@ManyToOne(fetch = FetchType.EAGER, optional = false)
@LastModifiedBy
@JoinColumn(name = "last_modified_by")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIdentityReference(alwaysAsId = true)
@JsonProperty("last_modified_user_id")
private User lastModifiedBy;

这是工作。但是一旦我尝试延迟加载列lastModifiedBy(fetch = FetchType.LAZY,optional = false)我就有错误:

2016-06-18 23:10:36,399 WARN  [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-8) Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Problem accessing property 'id': null (through reference chain: com.smcontact.cms.model.project.Project["manager"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Problem accessing property 'id': null (through reference chain: com.smcontact.cms.model.project.Project["manager"])

如何解决此错误?

1 个答案:

答案 0 :(得分:0)

解决方案:注册hibernate模块。

error: incompatible pointer types assigning to 'struct node *'
      from 'struct node **'; remove & [-Werror,-Wincompatible-pointer-types]
        root->children[1] = &root->children[1];
                          ^ ~~~~~~~~~~~~~~~~~~