transient in Hibernate field from database
I have hibernate @Entity
called Video
with fields:
@Column(name="TC_IN")
private BigDecimal tcIn;
@Column(name="TC_OUT")
private BigDecimal tcOut;
In the application, I need to convert the value to another format in order to use it.
So I added field:
@transient
private String formatTCOut;
public String getFormatTCOut(){
if (formatTCOut==null){
sysParamService = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBean("SysParamService");
formatTCOut = tcOut * sysParamService.findParamByNa开发者_高级运维me("accuracy");
}
return formatTCOut
}
Is it the right to invoke another service within entity of Hibernate?\
I have @Transactional( readOnly = true, propagation = Propagation.SUPPORTS )
above findParamByName
of the service?
In my opinion this is not a good design as it means your Hibernate object can now never be used outside of a web/JSF context.
This reduces the re-usability of the code and makes it hard to unit test.
Combining data/values from multiple beans or sources should be done at a higher level.
精彩评论