I want to override a bidirectional one-to-many with an index column mapping to an inverse mapping with order-by (I cannot change the model) to get rid of the index column in the database.
Example:
Code:
@Entity
public class ParentImpl {
@Id
@GeneratedValue
private long oid;
@OneToMany(targetEntity = ChildImpl.class)
@JoinColumn(name = "parent_oid")
@IndexColumn(name = "childIndex")
List<ChildImpl> children = new ArrayList<ChildImpl>();
}
Code:
@Entity
public class ChildImpl {
static final long serialVersionUID = 1;
@Id
@GeneratedValue
private long oid;
@ManyToOne(targetEntity = ParentImpl.class, fetch = FetchType.LAZY)
@JoinColumn(name = "parent_oid", insertable = false, updatable = false)
ParentImpl parent;
}
the xml to override should be
Code:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
version="1.0"
>
<package>de.mueller</package>
<entity class="ParentImpl" access="FIELD" metadata-complete="false">
<attributes>
<one-to-many name="children" mapped-by="parent" target-entity="de.mueller.ChildImpl" fetch="LAZY">
<order-by>oid</order-by>
</one-to-many>
</attributes>
</entity>
</entity-mappings>
I've tried also
<?xml version="1.0" encoding="UTF-8"?>
Code:
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
version="1.0"
>
<package>de.mueller</package>
<entity class="ChildImpl" access="FIELD" metadata-complete="false">
<attributes>
<many-to-one name="parent" target-entity="de.mueller.ParentImpl">
<join-column name="parent_o_id" insertable="true" updatable="true"/>
</many-to-one>
</attributes>
</entity>
<entity class="ParentImpl" access="FIELD" metadata-complete="false">
<attributes>
<one-to-many name="children" mapped-by="parent" target-entity="de.mueller.ChildImpl" fetch="LAZY">
<order-by>oid</order-by>
<join-column name="parent_o_id" insertable="false" updatable="false"/>
</one-to-many>
</attributes>
</entity>
</entity-mappings>
There is no problem with adding resp. setting the parent, but if the collection is loaded it uses the index column in sql.
Is there a way to get rid of the index column, or is this a bug?