Note that there are some explanatory texts on larger screens.

plurals
  1. POPlay2's Ebean Notation to Create Models
    text
    copied!<p>Ebean is using a very similar JPA annotation to map objects into a database. I've been checking out <code>@OneToOne @OneToMany @ManyToMany @ManyToOne</code> relationships.</p> <p>I just learned that inverse field is very inefficient (when use <code>@mappedBy</code> to determine a bidirectional relationship). </p> <p>I know normally, if I don't use ORM and just use SQL to create my own database structure, when I encounter this problem:</p> <p>Articles &lt;-> Tags</p> <p>This is a many to many relationship. An article can have many tags, and one tag can be attached to many articles.</p> <p>Normally, with SQL, I will create a Article table and a Tag table. Then I will create a separate table with two columns:</p> <p>Article_Tag Table:</p> <pre><code>PrimaryKey ID (int) ArticleID (int) ForeignKey to Article Table TagID (int) ForeignKey to Tag Table </code></pre> <p>Article Table:</p> <pre><code>PrimaryKey ArticleID (int) Article Title (varchar) </code></pre> <p>Tag Table:</p> <pre><code>PrimaryKey TagID (int) Tag Title (varchar) </code></pre> <p>My only problem now is how should/can I translate/rewrite this with Ebean(JPA) notation?</p> <p>First, do I need to create a model named Article_Tag in order for this Article_Tag table or is it created by Ebean automatically?</p> <p>Second, how should I annotate my article model and my tag model to describe this relationship? Which one is <code>@mappedBy</code> which one?</p> <p>Third, if I use <code>@mappedBy</code>, will it generate inverse field? Should I and how do I avoid using it?</p>
 

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