Here I am going to note down how to generate primary keys in hibernate.
Q : How do I drop a schema?
AnnotationConfiguration config=new AnnotationConfiguration();
config.addAnnotatedClass(Student.class);
config.configure("hibernate.cfg.xml");
new SchemaExport(config).drop(true, true);
ok lets see how to annotate a class to generate primary keys.
Note : Useful annotations
- @Table (name="TableName") : Specify a name for the table
- @Column(name="ColumnName") : Specify a column name
- @Column(nullable=false) : the specified column cannot be empty
- @Transient : The relevant attribute is volatile. not persistent
- @Basic : default annotation. if we don't give annotation. default one become Basic
- @Temporal(TemporalType.DATE) : used to annotate date types
- @Temporal(TemporalType.TIME) : used to annotate time
- @Temporal(TemporalType.TIMESTAMP) : used to annotate date and time (time stamp)
- @GeneratedValue : generate values automatically
- @GeneratedValue(strategy=GenerationType.TABLE, generator="stdId") most DBs support this type. and generate keys in a sequence. SEQUENCE type is not supported by DBDerby.