Skip to main content

Hibernate - Could not instantiate id generator [entity-name=domainObject]

Exception

Could not instantiate id generator [entity-name=Your DomainObject]

Solution 
<generator> or @GeneratedValue specifies the Java class that is used to generate a unique identifier to the mapped persistent class.

Using increment 

hbm.xml example

<id name="id" type="java.lang.Long" column="id">
       <generator class="increment" />
</id>

Annotation example

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID")
private Long id;

Using database sequence

hbm.xml example

<id name="id" type="java.lang.Long" column="id">
  <generator class="sequence">
    <param name="sequence">SEQ_PERSON_ID</param>
 </generator>
</id>

Annotation example

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="PERSON_SEQ")
@SequenceGenerator(name="PERSON_SEQ",sequenceName="SEQ_PERSON_ID", allocationSize = 1)
@Column(name="ID")
private Long id;

References
https://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html


Comments