-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: override IndexColumn by xml with order-by
PostPosted: Fri Aug 03, 2007 9:29 am 
Beginner
Beginner

Joined: Fri Nov 21, 2003 4:50 am
Posts: 23
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?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 2:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's not a bug, it's more like a limitation. the overriding doesnot support hibernate extensions mainly because we can not add our own namespace in orm.xml (against the spec AFAIK).
SO use hbm.xml files for such overriding.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 04, 2007 2:16 pm 
Beginner
Beginner

Joined: Fri Nov 21, 2003 4:50 am
Posts: 23
How can I use hbm.xml files for overriding single attributes ?
I always thought I can user either annotations or hbm.xml for mapping an entity.

Thanx for the answer Armin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 1:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hbm files does not override, you will have to rewrite the whole mappingfor this entity

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.