I have a One-to-Many-Relation between Parent and Child with the following mapping.
Code:
@Entity
public class Parent {
private List<Child> children;
@OneToMany(mappedBy = "parent")
@IndexColumn(name = "position")
@Cascade(value = { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
public List<Child> getChildren() {
return children;
}
}
@Entity
public class Child {
private Parent parent;
@ManyToOne(optional = false)
@JoinColumn(name = "mediaSequence_id", nullable = false)
public Parent getParent() {
return parent;
}
}
This works fine and I get two tables parent and child. The position row in the child table is correctly filled by Hibernate.
Now I wanted to explicitly add a position attribute to the Child class as I need to know the childs position at some time. Therefore I changed Child to:
Code:
@Entity
public class Child {
private Parent parent;
private int position;
@ManyToOne(optional = false)
@JoinColumn(name = "mediaSequence_id", nullable = false)
public Parent getParent() {
return parent;
}
@Column(name="position")
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
}
Now the position is not saved any more, but stays 0 in the database. Is my mapping incorrect or can't you add such an attribute to the Child class? I have read hibernate doc "2.4.6.2.1. Bidirectional association with indexed collections", but it didn't help me out.
I am using Hibernate 3.3.1.