我有一个Entity类,其中包含许多属性。
Hibernate在Spring引导初始化期间通过Hibernate AnnotationBinder正确发现属性,并且值从我们的数据库中正确获取,并通过Hibernate BasicExtractor正确映射到对象。
然而,在访问属性时,它们的值似乎来自过时的缓存版本。例如,它的值始终为null,而不是提取器日志中显示的值,我似乎无法弄清楚原因。值得注意的是:我可以保存到这个属性并让它保持正确,我只是不能从中读取
WHTFMain班
@Entity
@Table(name = "whtf_main")
public class WHTFMain {
...
@Column(nullable = true)
private String netsuiteId;
....
// getter/setter not shown
}
注释活页夹日志:
[main] TRACE org.hibernate.cfg.AnnotationBinder - Processing annotations of com.xxx.modules.netsuite.customRecords.WHTFMain.netsuiteId
[main] TRACE org.hibernate.engine.jdbc.env.internal.NormalizingIdentifierHelperImpl - Normalizing identifier quoting [netsuiteId]
[main] TRACE org.hibernate.engine.jdbc.env.internal.NormalizingIdentifierHelperImpl - Normalizing identifier quoting [netsuiteId]
[main] DEBUG org.hibernate.cfg.Ejb3Column - Binding column: Ejb3Column{table=org.hibernate.mapping.Table(whtf_main), mappingColumn=netsuite_id, insertable=true, updatable=true, unique=false}
[main] DEBUG org.hibernate.cfg.annotations.PropertyBinder - MetadataSourceProcessor property netsuiteId with lazy=false
[main] DEBUG org.hibernate.cfg.AbstractPropertyHolder - Attempting to locate auto-apply AttributeConverter for property [com.xxx.modules.netsuite.customRecords.WHTFMain:netsuiteId]
[main] DEBUG org.hibernate.cfg.annotations.SimpleValueBinder - building SimpleValue for netsuiteId
[main] TRACE org.hibernate.engine.jdbc.env.internal.NormalizingIdentifierHelperImpl - Normalizing identifier quoting [netsuiteId]
[main] TRACE org.hibernate.engine.jdbc.env.internal.NormalizingIdentifierHelperImpl - Normalizing identifier quoting [netsuiteId]
[main] TRACE org.hibernate.engine.jdbc.env.internal.NormalizingIdentifierHelperImpl - Normalizing identifier quoting [netsuiteId]
[main] DEBUG org.hibernate.cfg.annotations.PropertyBinder - Building property netsuiteId
[main] TRACE org.hibernate.cfg.annotations.PropertyBinder - Cascading netsuiteId with null
基本提取器日志(503是正确的值)
[ThreadPoolTaskScheduler-3] TRACE org.hibernate.type.descriptor.sql.BasicExtractor - extracted value ([netsuite8_1_1_] : [VARCHAR]) - [503]
查询:
public List<WHTFMain> findByMongoId(String mongoId) {
return entityManager.createQuery("select w from WHTFMain w where mongoId = :mongoId", WHTFMain.class)
.setParameter("mongoId",mongoId)
.getResultList();
}
被叫:
List<WHTFMain> whtfMainList = whtfDAO.findByMongoId(whtfMain.getMongoId());
检查:
netsuiteId = null