views:

295

answers:

0

We are using Hibernate Annotations 3.4.0GA and Hibernate Core 3.3.2.GA (also known as the current stable versions) against an Oracle database

We have a One-to-Many mapping with base=1 which worked fine for a loooong time, yet last week we found some entries in the database where the index column contained a value of 0 which caused all kinds of problems.

So my question is: Does anybody know of a way to get a value of 0 into the index column of a one-to-many relationship, when it is mapped with a base=1? Possibly related to the use generics or MappedSuperclass.

Note that code is rather complex, because inheritance is involved as well.

The following are the relevant pieces of the classes:

// SuperClass of the One side
@MappedSuperclass
public abstract class AbstractReihung<Tp, Tw, Te extends AbstractReihungElement<Tp, Tw>>
{
  @OneToMany(cascade = CascadeType.ALL)
  @Cascade(
  {
      org.hibernate.annotations.CascadeType.ALL,
      org.hibernate.annotations.CascadeType.DELETE_ORPHAN
  })
  @JoinColumn(name = "parent_id", nullable = false)
  @IndexColumn(name = "position", base = 1, nullable = false)
  private List<Te> elements = new ArrayList<Te>();
}

// Super Class of the Many side
@MappedSuperclass
public abstract class AbstractReihungElement<Tp, Tw> extends AbstractDbObject
{
  @ManyToOne
  @JoinColumn(name = "parent_id", insertable = false, updatable = false, nullable = false)
  private Tp parent;

  @Column(name = "position", insertable = false, updatable = false, nullable = false)
  private int position;
}

The actual classes inherit from these and provide concrete classes for the type parameters. They are mapped as Entity. They also specify id and version columns as well as tons of other attributes and references, but nothing related to the mapping at hand.