1

I'm trying to join a table with 2 conditions, userId and guideId are the same in both tables.

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "user_id",insertable =false, updatable = false)
@Where(clause = "guide_id = guide_id") <-- this isn't working
@LazyCollection(LazyCollectionOption.FALSE)
@NotFound(action = NotFoundAction.IGNORE)
private UserInvite userInvite;

Is this the right way to go about it?

I found some documentation around filters but this seems like an overkill. Is there a simple solution using the Where annotation?

beek
  • 3,522
  • 8
  • 33
  • 86

1 Answers1

1

Why don't you use @JoinColumns while specifying the relation:

@JoinColumns({
        @JoinColumn(name="user_id", referencedColumnName="user_id",insertable =false, updatable = false),
        @JoinColumn(name="guide_id", referencedColumnName="guide_id",insertable =false, updatable = false)
    })

If you are still adamant on using @Where , try using below clause:

@Where(clause = "guide_id = userInvite.guide_id")

Please make sure that guide_id is mapped as a field in your current entity where you are creating the relation

In case if the above clause doesn't work,let me know will figure it out in some other way

codeLover
  • 2,571
  • 1
  • 11
  • 27
  • Seems to work thank you! I had tried with JoinColumns but missed the referenceColumnName part. – beek Aug 08 '18 at 21:49