How to exclude a field from query

438 views
Skip to first unread message

Daryl Stultz

unread,
Aug 23, 2018, 1:03:32 PM8/23/18
to eb...@googlegroups.com
Hello,

We have an entity with an optional relation modeled like this:

@Entity
@Table(name = "scheduledassignments", schema = "public")
public class ScheduledAssignment {
    @OneToOne(mappedBy = "scheduledAssignment")
    private SwapOffer swapOffer; 

So this is the "opposite side" of the relation, SwapOffer has a foreign key to ScheduledAssignment. It is rare for us to need this field loaded. When we findList, the SwapOffer table is being left joined in and the Swap Offer ID selected. This join is really slowing things down. Is there any equivalent of "don't select/fetch" this field? I tried new FetchConfig().lazy() on the relation with no effect.

Is my only recourse to convert to raw sql?

Thanks.

/Daryl

Rob Bygrave

unread,
Aug 24, 2018, 1:39:19 AM8/24/18
to ebean@googlegroups
Interesting, I'll try to have a look over the next few days ...

A select() clause with only some properties should effectively exclude it but I'll have a look at the options.

Cheers, Rob.

--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob Bygrave

unread,
Aug 27, 2018, 4:05:21 AM8/27/18
to ebean@googlegroups
So yes, you have 2 options.

1. Use fetchType LAZY

    @OneToOne(mappedBy = "scheduledAssignment" , fetch = FetchType.LAZY)
    private SwapOffer swapOffer; 



2. use a select() clause (that doesn't include "swapOffer")

Which means the bean is partially loaded.


Assuming you want to not perform the join by default you'll probably look to use  fetch = FetchType.LAZY on the @OneToOne


See the following commit for a test case:


Cheers, Rob.

Daryl Stultz

unread,
Aug 27, 2018, 4:11:54 PM8/27/18
to eb...@googlegroups.com
On Mon, Aug 27, 2018 at 4:05 AM Rob Bygrave <robin....@gmail.com> wrote:
So yes, you have 2 options.

1. Use fetchType LAZY

    @OneToOne(mappedBy = "scheduledAssignment" , fetch = FetchType.LAZY)
    private SwapOffer swapOffer; 


Ah, excellent. I haven't specified FetchType on my entities since converting from JPA. I thought it wasn't necessary/effective. That should do the trick just fine. Sorry for the amateur question...

/Daryl

Rob Bygrave

unread,
Aug 27, 2018, 5:20:32 PM8/27/18
to ebean@googlegroups
No well not an amateur question at all.

With Ebean we really don't promote the use the fetch = FetchType.LAZY.   To me this issue looks like the one really really useful place for it in the Ebean context.  The other place it could be considered useful is for @Lob but by default we treat @Lob properties as lazy so really not useful there unless that is turned off (hence we basically never talk about FetchType.LAZY).

So this is good and this needs to go into the documentation on @OneToOne.


Cheers, Rob.

--
Reply all
Reply to author
Forward
0 new messages