Annotation @Basic to transient variables

橙三吉。 提交于 2019-12-23 09:40:42

问题


I am having a POJO class which consists of:
- persistent properties,
- transient properties.

While writing HQL I considered both: persistent and transient properties. I.e. HQL like select persistent_properties,transient_prop from Pojo_classname

is it correct?

Can I write @Basic annotation to transient variables?


回答1:


No, it's not correct. A HQL query translates to SQL. An @Transient property is not in the database, so the SQL query won't be able to query over this property.

@Basic and @Transient are contradictory. The first one tells "this property is persistent" and the second one tells "This property is not persistent".

If you're talking about the Java transient keyword, and not about the @Transient annotation, then yes, a transient field may be queried and annotated with @Basic. The transient keyword has nothing to do with persistence, only with binary serialization of the object.



来源:https://stackoverflow.com/questions/8267228/annotation-basic-to-transient-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!