With Hibernate 3.6 (may work with earlier versions as well, but I've not tested that), you can customise the hibernatetool code generation to skip creating constructors if they'd have more than 255 parameters, by creating the following file:
${hibernate-cust-src}/pojo/PojoConstructors.ftl
<#-- /** default constructor */ -->
public ${pojo.getDeclarationName()}() {
}
<#if pojo.needsMinimalConstructor() && pojo.getPropertiesForMinimalConstructor().size() lte 255> <#-- /** minimal constructor */ -->
public ${pojo.getDeclarationName()}(${c2j.asParameterList(pojo.getPropertyClosureForMinimalConstructor(), jdk5, pojo)}) {
<#if pojo.isSubclass() && !pojo.getPropertyClosureForSuperclassMinimalConstructor().isEmpty() >
super(${c2j.asArgumentList(pojo.getPropertyClosureForSuperclassMinimalConstructor())});
</#if>
<#foreach field in pojo.getPropertiesForMinimalConstructor()>
this.${field.name} = ${field.name};
</#foreach>
}
</#if>
<#if pojo.needsFullConstructor() && pojo.getPropertiesForFullConstructor().size() lte 255>
<#-- /** full constructor */ -->
public ${pojo.getDeclarationName()}(${c2j.asParameterList(pojo.getPropertyClosureForFullConstructor(), jdk5, pojo)}) {
<#if pojo.isSubclass() && !pojo.getPropertyClosureForSuperclassFullConstructor().isEmpty()>
super(${c2j.asArgumentList(pojo.getPropertyClosureForSuperclassFullConstructor())});
</#if>
<#foreach field in pojo.getPropertiesForFullConstructor()>
this.${field.name} = ${field.name};
</#foreach>
}
</#if>
this overwrites the PojoConstructors.ftl in the hibernate-tools.jar.
If you're using Ant to build, you'll need to ensure that the ${hibernate-cust-src}
is in the classpath for the hibernate-tools task.
<path id="toolslib">
<pathelement location="${hibernate-cust-src}"/>
... [other locations for hibernate-tools and dependencies]
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
Note, IMHO it's a bug in hibernate tools to create a constructor with >255 params...