开发者

transient in Hibernate field from database

开发者 https://www.devze.com 2023-02-11 01:48 出处:网络
I have hibernate @Entity called Video with fields: @Column(name=\"TC_IN\") private BigDecimal tcIn; @Column(name=\"TC_OUT\")

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消