I want Username = Administrator and Password = admin, soon after table is created (or whenever table is recreate).
- Is there any way to insert first row using following code. I do not want to use a separate insert query
-
Is there any constraint in Hibernate to restrict user from deleting (first) row
@Entity @Table(name = "Users") public class Users implements Serializable { @Id @Column(name = "Username", unique = true, nullable = false) private String username; @Column(name = "Password", nullable = false) private String password; /**************** getter & setter ************/ }
What you seem to be looking for is called fixtures. With Hibernate you can supply
import.sqlfile on your classpath with your initial data (insert statements).There’s a bit more information on the JBoss’ site.
The
import.sqlfile is a simple text file with SQL statements, one line per statement: