4

I have an enum as below.

public enum ExampleEnum {
    ONE(1), TWO(2);

    private int action;

    private ExampleEnum (int action){
        this.action = action;
    }

    /**
     * @return the action
     */
    public int getAction() {
        return action;
    }

    /**
     * @param action the action to set
     */
    public void setAction(int action) {
        this.action = action;
    }


}

I need to save integer values not ONE and TWO. how can i do that? i have below config in my hbm:

<property name="action">
            <column name="ACTION" />
            <type name="org.hibernate.type.EnumType">
                <param name="enumClass">com.ExampleEnum</param>
            </type>
        </property> 

Do i need to have any other configuration to save integers? Please help me!

Thanks!

user755806
  • 6,565
  • 27
  • 106
  • 153
  • `All persistent classes must have a default constructor (which can be non-public) so that Hibernate can instantiate them using Constructor.newInstance(). It is recommended that you have a default constructor with at least package visibility for runtime proxy generation in Hibernate.` – Aliaksei Bulhak Apr 05 '13 at 10:47
  • https://forum.hibernate.org/viewtopic.php?p=2377095 – Thihara Apr 05 '13 at 10:53
  • Possible duplicate. See this SO question: http://stackoverflow.com/questions/9839553/hibernate-map-enum-to-varchar?rq=1 – dcernahoschi Apr 05 '13 at 10:54

1 Answers1

0

`

<class name="package.class" table="database table name">
<id name="get/set parameter....your first attribute" type="int" column="data base columnname">
<generator class="increment"/><!--using auto increment-->
</id>
<property name="get/set parameter your second attribute">
<column name="data base column name"/>
</property>
</class>`
chandru
  • 1
  • 1