Tuplizers in Hibernate by R4R Team

org.hibernate.tuple.Tuplizer, and its sub-interfaces, are responsible for managing a particular representation of a piece of data given that representation's org.hibernate.EntityMode. If a given piece of data is thought of as a data structure, then a tuplizer is the thing that knows how to create such a data structure and how to extract values from and inject values into such a data structure. 

For example, for the POJO entity mode, the corresponding tuplizer knows how create the POJO through its constructor. It also knows how to access the POJO properties using the defined property accessors. 

There are two high-level types of Tuplizers, those represented by the:

1. org.hibernate.tuple.entity.EntityTuplizer
2. org.hibernate.tuple.component.

ComponentTuplizer interfaces. EntityTuplizers are responsible for managing the above mentioned contracts in regards to entities, while ComponentTuplizers do the same for components. Users can also plug in their own tuplizers. Perhaps require that a java.util.Map implementation other than java.util.HashMap be used while in the dynamic-map entity-mode. 

Or perhaps you need to define a different proxy generation strategy than the one used by default. Both would be achieved by defining a custom tuplizer implementation. Tuplizer definitions are attached to the entity or component mapping they are meant to manage. 

Going back to the example of our customer entity:

    <class entity-name="CustomerName">
            Override the dynamic-map entity-mode
            tuplizer for the customer entity
        <tuplizer entity-mode="dynamic-map"

        <id name="id" type="long" column="ID">
            <generator class="sequence"/>

        <!-- other properties -->

public class CustomMapTuplizerImpl23
        extends org.hibernate.tuple.entity.DynamicMapEntityTuplizer 
    // override the buildInstantiator() method to plug in our custom map...
    protected final Instantiator buildInstantiator(
            org.hibernate.mapping.PersistentClass mappingInfo) {
        return new CustomMapInstantiator( mappingInfo );

    private static final class CustomMapInstantiatorVe
            extends org.hibernate.tuple.DynamicMapInstantitor 
        // override the generateMap() method to return our custom map...
   protected final Map generateMap() {
   return new CustomMap();
Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!