Title: RE: [Xdoclet-user] Xdoclet 1.2b3 will not merge hibernate composite key

The class is more of a relational mapping, and not a true composite ID for another class,
so there is no getter method that returns the composite Id class.  I did try to put a private
getter/setter as a work around, but have not had success yet. 
so
/* @hibernate.class table="RelationTable"  */
public class SomeClass implements Serializable {
        public SomeClass(int compKeyOne, int compKeyTwo) {...}
        public int getCompKeyOne() {...}
        public int getCompKeyTwo() {...}
        public void setCompKeyOne(int key) {...}
        public void setCompKeyTwo(int key) {...}
        public boolean equals() { ... }
        public int hasCode() { ... }
}
became
/* @hibernate.class table="RelationTable"  */
public class SomeClass implements Serializable {
        public SomeClass(int compKeyOne, int compKeyTwo) {...}
       
        /* @hibernate.id generator-class="assigned" */
        private SomeClass getRelation() {
                return new SomeClass (getCompKeyOne(), getCompKeyTwo());
        }
        private void set(SomeClass sc) {
                this.setCompKeyOne(sc.getCompKeyOne());
                this.setCompKeyTwo(sc.getCompKeyTwo());
        }

        /* @hibernate.property */
        public int getCompKeyOne() {...}
        /* @hibernate.property */
        public int getCompKeyTwo() {...}

        public void setCompKeyOne(int key) {...}
        public void setCompKeyTwo(int key) {...}
        public boolean equals() { ... }
        public int hasCode() { ... }
}

which when generated results in the hbm.xml file looking like

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 1.1//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd">

<hibernate-mapping>
    <class
        name="com.brainbench.model.trial.ECPromoECItemRelation"
        table="ECPromoECItem"
    >

        <composite-id
            name="relation"
            class="com.brainbench.model.trial.ECPromoECItemRelation"
        >

                     <key-property
                        name="promoId"
                        type="int"
                        column="promoId"
                />

                     <key-property
                        name="itemId"
                        type="int"
                        column="itemId"
                />

        </composite-id>

        <property
            name="promoId"
            type="int"
            column="promoId"
        />

        <property
            name="itemId"
            type="int"
            column="itemId"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-ECPromoECItemRelation.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>

So far the mapping will load correctly but i start getting
duplicate property names in the hibernate queries,
i.e.
insert into SomeClassTable ( compKeyOne, compKeyTwo, compKeyOne, compKeyTwo) values ( ?, ?, ?, ? )
when it should be
insert into SomeClassTable ( compKeyOne, compKeyTwo ) values ( ?, ? )

Removing the @hibernate.property tags from the class removes the <property> and <key-property> elements
and results in a " Element "composite-id" requires additional elements. " XMLHelper error.

thanks.
eric.


> -----Original Message-----
> From: Konstantin Priblouda [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 03, 2003 4:28 AM
> To: [EMAIL PROTECTED]
> Subject: RE: [Xdoclet-user] Xdoclet 1.2b3 will not merge hibernate
> compos ite key
>
>
>
> --- Eric Mckenna <[EMAIL PROTECTED]> wrote:
> > I do have a class for the composite ID.  But it
> > stands alone, I use the
> > constructor
> > to create relations and either look them up if
> > existing or save them if they
> > are new relations.
> >
> > With the new b4 release, HibernateTagsHandler
> > changed, so
> > from my stack trace
> >
> > [hibernatedoclet] Caused by:
> > xdoclet.XDocletException: Class
> > com.brainbench.model.trial.ECPromoECItemRelation
> > misses ID property
> > [hibernatedoclet]       at
> >
> xdoclet.modules.hibernate.HibernateTagsHandler.hasCompositeId_
> Impl(Hibernate
> > TagsHandler.java:324)
> > [hibernatedoclet]       at
> >
> xdoclet.modules.hibernate.HibernateTagsHandler.ifHasPrimitiveI
> d(HibernateTag
> > sHandler.java:157)
> >
> > you can see that xdoclet is calling
> > ifHasPrimitiveId(), this method calls
> > hasCompositeId_Impl(template, false) which tells me
> > that I need something in
> > my class to tell xdoclet to use a composite id.
> >
> > My class which look likes this,
> >
> > /* @hibernate.class table="RelationTable" -- this is
> > the only hibernate tag
> > i previously needed */
> > public class SomeClass implements Serializable {
> >  public SomeClass(int compKeyOne, int compKeyTwo) {
> > ... }
> >  public int getCompKeyOne() {...}
> >  public int getCompKeyTwo() {...}
> >  public void setCompKeyOne(int key) {...}
> >  public void setCompKeyTwo(int key) {...}
> >  public boolean equals() { ... }
> >  public int hasCode() { ... }
> > }
> >
> > Does not have anything that would provide that
> > signal. Is there a different
> > xdoclet tag I should now use?
>
> You need a bit more of xdoclet tags :)
> 1. Put @hibernate.id on getter
> returning your composite id class use "assigned"
> generator
> 2. put @hibernate.property on respective properties of
> your composite id class.
>
> When in doubt - use recent CVS version.
>
> regards,
>
> =====
> ----[ Konstantin Pribluda ( ko5tik ) ]----------------
> Zu Verstärkung meines Teams suche ich ab Sofort einen
> Softwareentwickler[In] für die Festanstellung.
> Arbeitsort: Mainz
> Skills:  Programieren, Kentnisse in OpenSource-Bereich
> ----[ http://www.pribluda.de ]------------------------
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> xdoclet-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/xdoclet-user
>

Reply via email to