Does Hibernate create tables in the database automatically

后端 未结 8 1171
庸人自扰
庸人自扰 2020-12-01 07:23

Upon reading this (archived) tutorial, they have not mentioned anything over creating tables in the DB. Does the Hibernate handle it automatically by creating tables and fie

8条回答
  •  失恋的感觉
    2020-12-01 08:07

    add following property in your hibernate.cfg.xml file

    update

    BTW, in your Entity class, you must define your @Id filed like this:

    @Id
    @GeneratedValue(generator = "increment")
    @GenericGenerator(name = "increment", strategy = "increment")
    @Column(name = "id")
    private long id;
    

    if you use the following definition, it maybe not work:

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private long id;
    

提交回复
热议问题