Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigned Generator Class on Hibernate Annotations

Hibernate newbie here. I am working on a simple Hibernate mapping file. When I am using the xml approach, I set the generator class to assigned. There are certain logic that must be checked before an employee id is assigned so I cant generate it automatically.

<id name="id" type="string" column="emp_id">
        <generator class="assigned">
        </generator>
</id>

But I am also studying the annotation type and annotation seems to be in thing nowadays as frameworks are moving away from configuration files. But I cant find any generation type to match the assigned value

public class Employee{
 String id; 
 @column(name="emp_id", unique=true)
 public String getID(){
  return id;
 }
}

Does this mean that I dont need to add any sequence generator annotation when it is assigned? Thanks

like image 295
Mark Estrada Avatar asked Jan 05 '11 10:01

Mark Estrada


1 Answers

Just use the @Id annotation which lets you define which property is the identifier of your entity. You don't need to use the @GeneratedValue annotation because I don't think you want hibernate to generate this property for you.

@Id
String id; 
like image 135
dogbane Avatar answered Sep 21 '22 18:09

dogbane