首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LastModifiedBy

LastModifiedBy
EN

Stack Overflow用户
提问于 2016-06-18 23:12:15
回答 1查看 142关注 0票数 0

如何延迟加载带有@LastModifiedBy注释的多对一列?

例如,我有createdBy和lastModifiedBy列:

代码语言:javascript
复制
@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,可选= false)时,我就出错了:

代码语言:javascript
复制
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"])

如何修复此错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-19 12:41:04

解决方案:注册hibernate模块。

代码语言:javascript
复制
Hibernate5Module hibernateModule = new Hibernate5Module();
objectMapper.registerModule(hibernateModule);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37902464

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档