Note that there are some explanatory texts on larger screens.

plurals
  1. POMarking a pair of @ManyToOne related properties as unique. Possible?
    primarykey
    data
    text
    <p>I have the typical example, where a POST has many TAGS, and a TAG has many POSTs. Instead of using a typical <code>@ManyToMany</code>, I use a domain object in the middle, called TAGPOST, which also allows me to have useful data in there, such as when a post was tagged with a given tag, etc. Each POST, and TAG resp, is in a <code>@OneToMany</code> relationship with a TAGPOST.</p> <p>The specific requirement is that a post cannot have the same tag included twice, therefore the TAGPOST.post and TAGPOST.tag pair must always be unique. Normally, I would do that by making a composite primary key pair in the table, responsible for storing TAGPOST objects. </p> <p>AFAIK, there is no way to express this unique constraint. I have marked <code>jpa.ddl=update</code>, which means that every time I move the application to a new environment, I will have to go and manually fix this in the DB. This is very inconvenient, and error prone, especially when unit testing, because then the database is created and dropped more or less in every iteration. </p> <p>I was even thinking to do the check manually on <code>@PrePersist</code>, or even move the check in a business layer, say, create a PostService.</p> <p>What do I do? Am I missing something that Play has by default? Some clever annotation to express the uniqueness of the <code>@ManyToOne</code> properties of the TAGPOST class?</p> <p>FYI: I am using Play 1.2.5</p> <p>EDIT: The TAGPOST class looks like this:</p> <pre><code>@Entity public class TagPost extends Model { @ManyToOne public Tag tag; @ManyToOne public Post post; public Date dateAdded; ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload