问题
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