0

I am new to hibernate and how annotations can create tables in database. I think what is wanted is related with : this question, but I am not sure

Suppose there is a class Ticket like this :

@Entity
public class Ticket {

    @ManyToMany 
    private Set<Person> buyers;

    @ManyToMany
    private List<Person> collectors;

         ...
         ...

}

The below line creates a table ticket_person as wanted:

private Set<Person> buyers;

But the next line, again the class Person is used in object collectors, so table ticket_person can't be created again, but there is a need to have both objects buyers and collectors. So how to get round the problem ? Is there any way in which the default table name ticket_person can be overridden ? Or any other solution that lets create 2 tables with same fields but for different objects in the entity ?

Community
  • 1
  • 1
Anubha
  • 1,345
  • 6
  • 23
  • 35

1 Answers1

1

That is work for Jointable annotation. As can be seen from the API documentation, all the attributes are optional. In this case only name of the join table should be affected, so following is enough:

@JoinTable(name= "ticket_to_collectors")
@ManyToMany
private List<Person> collectors;
Mikko Maunu
  • 41,366
  • 10
  • 132
  • 135