# Composite id with a complex type as one of its members

**URL:** <https://discourse.hibernate.org/t/composite-id-with-a-complex-type-as-one-of-its-members/960>\
**Category:** Hibernate ORM\
**Created:** [June 25, 2018, 4:26pm UTC](https://discourse.hibernate.org/t/composite-id-with-a-complex-type-as-one-of-its-members/960 "2018-06-25T16:26:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpcaldeira](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/rpcaldeira/32/228_2.png) [@rpcaldeira](https://discourse.hibernate.org/u/rpcaldeira)\
**Post date:** [June 25, 2018, 4:26pm UTC](https://discourse.hibernate.org/t/composite-id-with-a-complex-type-as-one-of-its-members/960/1 "2018-06-25T16:26:06Z")

</div>

Hello all, I’m new here and need to perform an operation but i don’t know if it is possible.

Right now I have a composite Id as such:

```auto
<composite-id name="a" class="com.b.c.d.e.s">
            <key-property name="a" access="field" column="A" type="int"/>
            <key-property name="b" access="field" column="B" type="int"/>
            <key-property name="c" access="field" column="C" type="java.lang.Long"/>

            <key-property name="d" access="field" column="D" type="int"/>
            <key-property name="e" access="field" column="E" type="int"/>
            <key-property name="f" access="field" column="F" type="java.lang.Long"/>

            <key-property name="g" column="G" type="com.h.y.g.x"/>
        </composite-id>

```

I need to create a new composite-id that contains the old composite id and a new primitive integer.  
I tried something like this but it is not supported. Can anyone help me?

```auto

        <composite-id name="newID" class="com.a.b.c.d.e.f.newId">
            <key-property name="formerID" type="formerID"/>
            <key-property name="num" access="field" column="NUM" type="int"/>
        </composite-id>

<composite-id name="formerID" class="com.b.c.d.e.s">
            <key-property name="a" access="field" column="A" type="int"/>
            <key-property name="b" access="field" column="B" type="int"/>
            <key-property name="c" access="field" column="C" type="java.lang.Long"/>

            <key-property name="d" access="field" column="D" type="int"/>
            <key-property name="e" access="field" column="E" type="int"/>
            <key-property name="f" access="field" column="F" type="java.lang.Long"/>

            <key-property name="g" column="G" type="com.h.y.g.x"/>
        </composite-id>

```

Thanks in advance and best regards,  
Rui

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 26, 2018, 6:05am UTC](https://discourse.hibernate.org/t/composite-id-with-a-complex-type-as-one-of-its-members/960/2 "2018-06-26T06:05:43Z")

</div>

I don’t think that composite identifiers can be composed like that. However, you can just do that by copying the properties to the new identifier:

```
 <composite-id name="newID" class="com.a.b.c.d.e.f.newId">
        <key-property name="num" access="field" column="NUM" type="int"/>

        <key-property name="a" access="field" column="A" type="int"/>
        <key-property name="b" access="field" column="B" type="int"/>
        <key-property name="c" access="field" column="C" type="java.lang.Long"/>

        <key-property name="d" access="field" column="D" type="int"/>
        <key-property name="e" access="field" column="E" type="int"/>
        <key-property name="f" access="field" column="F" type="java.lang.Long"/>

        <key-property name="g" column="G" type="com.h.y.g.x"/>
    </composite-id>
```

---

<div class="post-metadata">

**Author:** ![rpcaldeira](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/rpcaldeira/32/228_2.png) [@rpcaldeira](https://discourse.hibernate.org/u/rpcaldeira)\
**Post date:** [June 26, 2018, 11:06am UTC](https://discourse.hibernate.org/t/composite-id-with-a-complex-type-as-one-of-its-members/960/3 "2018-06-26T11:06:29Z")

</div>

It worked!

Thank you so much 🙂
