Marc Schipperheyn edited a comment on Bug HHH-5732

I've done some testing and I can confirm that if you follow the 4.1

A

public class Parent{
@OneToMany(cascade={ CascadeType.ALL },orphanRemoval=true,fetch=FetchType.LAZY)
@JoinColumn(name="FK_ParentId",nullable=false)
@LazyCollection(LazyCollectionOption.EXTRA)
@OrderColumn(name="idx")
public List<Child> getChildren()

[...]
public class Child{
//no idx attribute
@ManyToOne(fetch=FetchType.LAZY,optional=false)
@JoinColumn(name="FK_ParentId",nullable=false, insertable=false,updatable=false)
public Parent getParent() {

B

public class Parent{
@OneToMany(cascade={ CascadeType.DELETE },orphanRemoval=true,mappedBy="parent",fetch=FetchType.LAZY)
@LazyCollection(LazyCollectionOption.EXTRA)
@OrderColumn(name="idx")
public List<Child> getChildren()

[...]
public class Child{

@Column
private int idx;

@ManyToOne(fetch=FetchType.LAZY,optional=false)
@JoinColumn(name="FK_ParentId",nullable=false)
public Parent getParent() {

documentation(http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-hibspec-collection-extratype-indexbidir), and
A. remove the mappedBy, ExtraLazy access seems to be out of the window. Every collection.get leads to full initialization of the collection.

B. with the other option in the documentation where mappedBy is used and an extra idx attributes is added to the child, I'm seeing the idx being 0 every time (Hibernate 4.1.7).

C. not adding the idx attribute to Child leads to it being left null. But B and C seem to be the same: idx is not managed by Hibernate.

In both cases I'm doing
child.setParent(parent);
parent.getChildren().add(child);

parent = dao.save(parent);

dao.flush();

case A saves correctly, but ExtraLazy element fetching doesn't work.
case B, idx is always 0

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira