You can have two one to one relationships, like so:
class Costumer {
@OneToOne
Ticket ownTicket;
@OneToOne
Ticket refererTicket;
}
Just give different names. And then, in the Ticket class, if you do want to map both ways, I believe you have to use the mappedBy property:
class Ticket {
@OneToOne(mappedBy="ownTicket")
Costumer owner;
@OneToOne(mappedBy="refererTicket")
Costumer referer;
}
If Ticket can have only one Costumer, then this is what I would do:
Create a relationship class, called TicketCostumer
or something:
class TicketCostumer {
@OneToOne
Ticket ticket;
@ManyToOne
Costumer costumer;
Type type;
}
Where Type is an enum you create that has OWNER and REFERER;
Now each ticket can have only one of this:
class Ticket {
@OneToOne
CostumerTicket ct;
}
And finally, on Costumer, you can decide how to handle things; you could have a list and guarantee by hand that there is not more than one of each kind (or try to use the @UniqueBy or something like that), or you can have two separated fields to control it.