Hi I have written code like this
@Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() { return UserID; }
But I manually setting it from DAO like "e.setUserID(01);" to insert.Otherwise row not inserting Is there any process to get value to id and retrieve what value generated automatically. Im thinking i will get some help
Use the IDENTITY generation type instead of auto. Use a Long for id. I also recommend changing the name from UserID to userId. Do not forget the @Entity for the class name.
@Entity
public class MyClass{
private Long userId;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column
public Long getUserID(){
return userId;
}
//.. rest of class
}
Be very careful with the naming conventions and make sure your field names and types match the field names and types from the database.
Use
@GenericGenerator(name="generator", strategy="increment")
@GeneratedValue(generator="generator")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With