开发者

HQL query minus some specific fields

开发者 https://www.devze.com 2023-02-14 21:13 出处:网络
It is possible with a HQL query to retrieve every fields EXCEPT one. Something like : session.get(entityClass, id).withoutThisField(fieldNotDesired)

It is possible with a HQL query to retrieve every fields EXCEPT one.

Something like :

session.get(entityClass, id).withoutThisField(fieldNotDesired)

Example : I have a class Picture(int id, String name , byte[] file).

I want to retrieve all pictures except the field file.

I know I can do it if I precise the fields wanted but I don't want to update my query every time a new field is added.

I know if the field is a blob, it will be retrieve only if necessa开发者_开发技巧ry. It is not my case.

And bytecode instrumentation to precise a field lazy=true doesn't work, I have weird exceptions.

Thanks in advance.


I'd suggest using an inherited class.

Have the PictureFile be a subclass of Picture that adds just the one field file.

In your example, you can just get the Picture. When you do need to file blob, get the PictureFile.

I find myself frequently creating several alternative mappings for entities, based on specific needs like this.

0

精彩评论

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