HQL query minus some specific fields
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 fieldlazy=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.
精彩评论