Hibernate – @uniqueConstraint Checks multiple tables in JPA

The @OneToMany building on campus has @OneToMany guest rooms.
Room names must be unique on campus
(e.g. campus-A, block-A, room-A and Campus-B, block-A, room-A should be able to store)

Is it possible to define such a unique constraint on the Room entity?

I may be missing something here, but there is no unique name established on campus? Therefore, you need to ensure that the room name is unique within a given building:

@Entity
@Table(name="rooms",< br /> uniqueConstraints = {@UniqueConstraint(columnNames={"building_id","name"})}
)
public class Room {
...
@ManyToOne
@JoinColumn(name = "building_id")
private Building building;
...
}

If you do the same for the building name on campus now Thing, then you should go well.

@OneToMany建筑 has @OneToMany guest rooms on campus.
The room name must be unique on campus
(e.g. Campus-A, block-A, room-A and campus-B, block-A, room-A should be able to store)

Is it possible to define such a unique constraint on the Room entity?

I may have missed something here, but there is no unique name established on campus? Therefore, you need to ensure that the room name is unique within a given building:

@Entity
@Table(name="rooms",< br /> uniqueConstraints = {@UniqueConstraint(columnNames={"building_id","name"})}
)
public class Room {
...
@ManyToOne
@JoinColumn(name = "building_id")
private Building building;
...
}

If you do the same for the building name on campus now Thing, then you should go well.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4446 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.