Home > database >  Can we create tables in a database without making the interface of a repository
Can we create tables in a database without making the interface of a repository

Time:10-13

Can we create tables in a database without making the interface of a repository

this is my entity class

@Entity
@Table
public class Employ {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String firstname;
    private String lastname;
    private String address;

this is my repository

public interface EmployRepo extends CrudRepository<Employ, Integer> {
}

CodePudding user response:

Yes, basically, when you mention @Entity in an entity class it will automatically generate the table in your database, the Table will be generated even if you do not create the Repository, but we create the interface of a repository to make a connection between the database and the program, and also to perform CRUD operations,

and mention the @Repository annotation above the repository is used to indicate that the class is a Repository used to perform CRUD operations.

@Repository
public interface EmployRepo extends CrudRepository<Employ, Integer> {
}
  • Related