4

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 necessary. It is not my case.
And bytecode instrumentation to precise a field lazy=true doesn't work, I have weird exceptions.

Thanks in advance.

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.