views:

21

answers:

1

I have a class that sometimes is not necessary to load fully. Can I load it partially, or I need to create light version of class (and new mappings for it)?

For example: class Message with id, title, body, author, timestamp. When I want to delete message i need only two fields id, author.

+1  A: 

I have a class that sometimes is not necessary to load fully. Can I load it partially, or I need to create light version of class (and new mappings for it)?

In theory, Hibernate can do lazy property loading if you use buildtime bytecode instrumentation. See 19.1.7. Using lazy property fetching. But I don't have much experience with that, I tend to prefer the "light version" approach if really required.

For example: class Message with id, title, body, author, timestamp. When I want to delete message i need only two fields id, author.

This may not the best example as you could maybe use a bulk HQL DELETE here (which is in general much more efficient than loading Message instances and looping over them to delete them). See the section 13.4. DML-style operations. But if you can't, then loading an entity to delete it is the price to pay when using an ORM.

Pascal Thivent