I found a very dirty solution, that I would not recommend, but it works for me.
I changed the template PojoConstructors.ftl to remove any parameter from the constructor, that ends with "id".
But just think about a parameter named "stupid" - this would not show in the constructor, allthough it may not be an Id.
So... in my case I have to make sure, that no table column name ends with "id".
For this purpose, I defined the following macro within PojoConstructors.ftl:
Code:
<#-- /** returns the list of parameters seperated by comma, but without the id parameter */ -->
<#macro removeIdParam paramString>
<#list paramString?split(",") as x><#if !x?ends_with("id")>${x}<#if x_has_next>,</#if></#if></#list>
</#macro>
Then later on, I call:
Code:
<#if pojo.needsMinimalConstructor()> <#-- /** minimal constructor */ -->
/**
* minimal constructor.
*
<#foreach field in pojo.getPropertiesForMinimalConstructor()><#if !field.name?ends_with("id")>
* @param ${field.name}
</#foreach> */
<#-- /** remove id parameter from constructor */-->
<#if c2j.asParameterList(pojo.getPropertyClosureForMinimalConstructor(), jdk5, pojo).contains("Id")>
//Id is removed
public Abstract${pojo.getDeclarationName()}(<@removeIdParam paramString=c2j.asParameterList(pojo.getPropertyClosureForMinimalConstructor(), jdk5, pojo)/>) {
<#else>
//no Id found
public Abstract${pojo.getDeclarationName()}(${c2j.asParameterList(pojo.getPropertyClosureForMinimalConstructor(), jdk5, pojo)}) {
</#if>
<#if pojo.isSubclass() && !pojo.getPropertyClosureForSuperclassMinimalConstructor().isEmpty()>
super(${c2j.asArgumentList(pojo.getPropertyClosureForSuperclassMinimalConstructor())});
</#if>
<#foreach field in pojo.getPropertiesForMinimalConstructor()>
<#if !field.name?ends_with("id")> this.${field.name} = ${field.name};</#if>
</#foreach>
}
</#if>
It is a very dirty hack and I do not recommend doing it like this.