In my Hibernate Application i\'m using create a ValueObject class
@Entity
@Table(name=\"user\")
public class UserVO{
@Id
@Column(name=\"S_ID\")
as @vinit said :
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name="S_ID")
private String s_id;
is the best choice ...
If you are using a trigger, the intended generation strategy is org.hibernate.id.SelectGenerator
. However, in order to use this strategy, Hibernate must be able to locate the inserted row after insertion to see what value the trigger assigned there are 2 ways to do this.
First is to specifically configure the generator to tell it a column that define a unique key (at least logically) within the table:
@Id
@Column(name="S_ID")
@GeneratedValue( strategy = "trigger" )
@GenericGenerator(
name="trigger", strategy="org.hibernate.id.SelectGenerator",
parameters = {
@Parameter( name="keys", value="userName" )
}
)
private String s_id;
private String userName;
The other is via Hibernate's natural-id support:
@Id
@Column(name="S_ID")
@GeneratedValue( strategy = "trigger" )
@GenericGenerator( name="trigger", strategy="org.hibernate.id.SelectGenerator" ) )
private String s_id;
@NaturalId
private String userName;
GenerationType.IDENTITY may work for you. It will really come down to the JDBC driver and how (if) it implements getGeneratedKeys
ID column must not be null, whatever you do in database driver, will only be trigger before/after insert or any other operation, But according to error it is giving error before any error.
Set something to ID values or try something
@GeneratedValue(strategy = GenerationType.IDENTITY)