Maybe I'm missing something, but they donβt build names that are unique on campus? Therefore, you need to make sure that the room names are unique within the given building:
@Entity @Table(name="rooms", uniqueConstraints = {@UniqueConstraint(columnNames={"building_id","name"})} ) public class Room { ... @ManyToOne @JoinColumn(name = "building_id") private Building building; ... }
If you are now doing the same for the Building names inside Campus , you should be good to go.
source share