christian wrote:
There are no workarounds or association tables necessary. Just copy and paste the example from the documentation:
http://hibernate.org/hib_docs/annotatio ... -extratypeYou need to understand what "inverse" (or "mappedBy", which is the same) means. There are plenty of documents around, including a whole page on the wiki.
Hi Christian
Many thanks for pointing me to this section. I read this section several times, I will show you what happens in my scenarios...
And BTW: Section 2.4.6.2.3 of this documentation is very confusing. I assume the 2nd class in the first examples is the CHILD rather than parent.
Anyhow, back to "my" problem.
a, b, c is referring back to my code in the first post!
(a) INVERSE
Here the following table structure is created:
Parent(*parentID)
Child(*childID, parentID, position)
Ideal, the table structure at least.
childIDs and parentIDs are inserted.
BUT the position remain always always 0.
WHY :((( ???
(b)
Here the following table structure is created:
Parent(*parentId)
Parent_Child(*parentID, childID, *position)
Child(*childID, parentID, parent_parentID)
This introduces some redundancy which certainly is far from ideal.
However, the position is now actually filled in properly ;)
And this solution is in line with the documentation
http://hibernate.org/hib_docs/annotatio ... -extratype
Am I missing something ? That can't be right...
(c)
I'd be VERY great full if one can point out to me how to obtain the rank from the Child a bit more elegant than "parent.getChildren().indexOf(this)".
What Annotation do I need to *query* the rank from the DB ?
Code:
@Entity
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long childID;
@ManyToOne
private Parent parent;
@NO IDEA HOW TO ANNOTATE THIS TO GET THE INDEX FROM THE DB!
private position;
}
Sorry to bother with this for you maybe simple/silly stuff. Everything works great for me, my whole mapping works, except this little small annoying thing which I can't solve properly.
I hope for yet another hint. Thank you so much!