JPA / Hibernate Select the Column on Join submenu

In SQL, it is easy to join and return only the columns you need from the joined table. What is the best way to map this in JPA / Hibernate?

For example, there is a Folder object mapped to EMAIL_FOLDER and an email object displayed in the EMAIL table. There is a one-to-many relationship from folder to email. The email object is pretty heavy because it contains CLOB text, attachments, etc. There are some cases when we need to return all the email, and there are other cases when we just want to return senderName, subject and sentDate and do not want the memory overhead when entering CLOB data. Doing this in SQL is simple, but I'm not sure what the best approach would be in JPA / Hibernate.

I am thinking of creating LightEmail that only maps to senderName, subject, and sentDate. Is this the best way to deal with something like this?

Update: at this point, I would like, if possible, to avoid using byte code.

+3
source share
1 answer

Annotate Property (CLOB) as @Basic(fetch=FetchType.LAZY)

See Declaring Basic Property Mappings in the Hibernate Reference

+1
source

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


All Articles