# Change composite-id property name with Delegating Reverse Engineering Strategy

**URL:** <https://discourse.hibernate.org/t/change-composite-id-property-name-with-delegating-reverse-engineering-strategy/6783>\
**Category:** Hibernate Tools\
**Created:** [October 15, 2022, 5:05pm UTC](https://discourse.hibernate.org/t/change-composite-id-property-name-with-delegating-reverse-engineering-strategy/6783 "2022-10-15T17:05:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccamusso](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@ccamusso](https://discourse.hibernate.org/u/ccamusso)\
**Post date:** [October 15, 2022, 5:05pm UTC](https://discourse.hibernate.org/t/change-composite-id-property-name-with-delegating-reverse-engineering-strategy/6783/1 "2022-10-15T17:05:09Z")

</div>

I have this table with composite primary key:

```auto
CREATE TABLE `arc_test` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `data` datetime DEFAULT NULL,
  `text` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`,`data`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

```

and this hibernate reverse engineering configuration:

```auto
<hibernate-reverse-engineering>  
    <table name="arc_test" catalog="db">
        <primary-key>
            <generator class="native"/>
        </primary-key>       
    </table> 
</hibernate-reverse-engineering> 

```

and this revenge.strategy

```auto
public class CustomReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy {

    public CustomReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
        super(delegate);
    }

    public String columnToPropertyName(TableIdentifier table, String column) {
    	if("arc_test".equals(table.getName()) && "id".equalsIgnoreCase(column))
    		return "compositeId";
        else
    		return super.columnToPropertyName(table, column);
    }
}

```

Hibernate Tools generated this two class:

```auto
public class ArcTest implements java.io.Serializable
{
    private ArcTestId id;
    private String text;
    .....
    .....

public class ArcTestId implements java.io.Serializable
{
    private Integer compositeId;
    private Date data;
        .....
        .....

```

is it possible with DelegatingReverseEngineeringStrategy class customization change property name of composite-id, like this

```auto
public class ArcTest implements java.io.Serializable
{
    private ArcTestId **compositeId** ;
    private String text;
    .....
    .....

```

is it possible with reveng strategy?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [October 17, 2022, 9:43am UTC](https://discourse.hibernate.org/t/change-composite-id-property-name-with-delegating-reverse-engineering-strategy/6783/2 "2022-10-17T09:43:26Z")

</div>

I don’t understand the question. You already use a `CustomReverseEngineeringStrategy` and provide a custom name and showed that it does generate what you seem to expect. What’s the issue?

---

<div class="post-metadata">

**Author:** ![ccamusso](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@ccamusso](https://discourse.hibernate.org/u/ccamusso)\
**Post date:** [October 17, 2022, 10:11am UTC](https://discourse.hibernate.org/t/change-composite-id-property-name-with-delegating-reverse-engineering-strategy/6783/3 "2022-10-17T10:11:15Z")

</div>

Yes, I use CustomReverseEngineeringStrategy.  
But **tableToCompositeIdName** method, change only the entity class name of composite-id

```auto
public String tableToCompositeIdName(TableIdentifier identifier) {
    if("arc_test".equals(identifier.getName()))
    	return "CompositIDClass";
    else
    	return super.tableToCompositeIdName(identifier);
}

```

this is the outptut

```auto
public class ArcTest implements java.io.Serializable
{
    private CompositIDClass id;
    private String text;
    .....
    .....

```

and **columnToPropertyName** method change only property name inside entity class of composite-id

```auto
public String columnToPropertyName(TableIdentifier table, String column) {
    	if("arc_test".equals(table.getName()) && "id".equalsIgnoreCase(column))
    		return "compositeId";
    	else
    		return super.columnToPropertyName(table, column);
    }

```

this is the outptut

```auto
public class ArcTestId implements java.io.Serializable
{
    private Integer compositeId;
    private Date data;
        .....
        .....

```

I need change property name of composite-id property inside POJO entity class, like this:

```auto
public class ArcTest implements java.io.Serializable
{
    private ArcTestId compositeId;
    private String text;
    .....
    .....

```

Is possible?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [October 17, 2022, 12:33pm UTC](https://discourse.hibernate.org/t/change-composite-id-property-name-with-delegating-reverse-engineering-strategy/6783/4 "2022-10-17T12:33:09Z")

</div>

If you take a look into the code, you will see how this works and how the `columnToPropertyName` method is called. See [hibernate-tools/PrimaryKeyBinder.java at 6.1.4.Final · hibernate/hibernate-tools · GitHub](https://github.com/hibernate/hibernate-tools/blob/6.1.4.Final/orm/src/main/java/org/hibernate/tool/internal/reveng/binder/PrimaryKeyBinder.java#L135) for details about how the primary key property name is determined.

You just have to override the `tableToIdentifierPropertyName` method.

---

<div class="post-metadata">

**Author:** ![ccamusso](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@ccamusso](https://discourse.hibernate.org/u/ccamusso)\
**Post date:** [October 17, 2022, 1:57pm UTC](https://discourse.hibernate.org/t/change-composite-id-property-name-with-delegating-reverse-engineering-strategy/6783/5 "2022-10-17T13:57:03Z")

</div>

Ok I have a problem 😀  
My project use Java 8 and Hibernate 5.6.  
tableToIdentifierPropertyName not exist in DelegatingReverseEngineeringStrategy (5.6 distro)

If I want to use Hibernate 6.1 a need migrate to Java 11, is not fast for my project.

Thanks anyway

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [October 17, 2022, 4:10pm UTC](https://discourse.hibernate.org/t/change-composite-id-property-name-with-delegating-reverse-engineering-strategy/6783/6 "2022-10-17T16:10:22Z")

</div>

Did you look into the source code in your project? AFAICT it is possible: [hibernate-tools/ReverseEngineeringStrategy.java at 5.6.12.Final · hibernate/hibernate-tools · GitHub](https://github.com/hibernate/hibernate-tools/blob/5.6.12.Final/main/src/main/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategy.java#L115)
