Hello
I am using Hibernate 4.1.0.Final with Spring 3
I have the following in Entity class
Code:
@Id
@Column(name = "PROJECT_NO")
@GeneratedValue(strategy=GenerationType.TABLE)
private String projectNumber;
Is it possible to use database trigger to populate the primary key of a table?
Or I have to use a CustomGenerator for this? i.e. trigger on my table will be used to insert primary key value rather than
Hibernate doing it.
In database trigger I have the following to populate value
Code:
SELECT NVL (MAX (project_no), 0) + 1 FROM projects
Any help is highly appreciable?
Edit, If I try with the following I am getting
Code:
:org.hibernate.id.IdentifierGenerationException:no natural-id property defined;
need to specify [key] in generator parameters
Code:
@Id
@GeneratedValue(generator="triggerAssigned")
@GenericGenerator(name="triggerAssigned",
strategy = "org.hibernate.id.SelectGenerator",parameters = {
@Parameter( name="keys", value="projectNo" )
})
@Column(name = "PROJECT_NO")
public int getProjectNo() {
return projectNo;
}