HQL query minus certain fields

You can get all EXCEPT fields in an HQL query.

Sort of:

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

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

I want to get all the snapshots except the field file.

I know that I can do this if I clarify the required fields, but I do not want to update my query every time a new field is added.

I know if the field is a blob, it will be retrieved only if necessary. This is none of my business.
And the bytecode tool for the exact field lazy=true does not work, I have strange exceptions.

Thanks in advance.

+4
source share
1 answer

I would suggest using an inherited class.

PictureFile has a subclass of Picture that adds only one field file.

In your example, you can just get the image. When you need to write blob, get PictureFile.

I often find several alternative mappings for entities based on specific needs like this.

+1
source

Source: https://habr.com/ru/post/1341994/


All Articles