欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springboot结合hibernate jpa自动创建数据表

程序员文章站 2022-05-04 16:26:35
...

实体类一定要写对 仔细检查实体类的注解 字段类型
之前一直可以正常启动 但就是创建不了表 也不提示错误 不知道是什么原因导致自动创建表失败
先仔细检查实体类 字段类型 各个实体类之间的联系字段有没有写对
pom.xml中的依赖有没有引入
检查application-dev,yml中数据库的链接配置有没有问题

之前在 Blog.java中 这个字段的类型写错了

 @OneToMany(mappedBy = "blog")
    private Comment comments = new Comment();//一个博客对应多条评论

改成下面后

 @OneToMany(mappedBy = "blog")
    private List<Comment> commentslist = new ArrayList<>();//一个博客对应多条评论

重新生成这个字段的getter setter方法
再启动 自动创建表成功

Hibernate: create table hibernate_sequence (next_val bigint) engine=InnoDB
Hibernate: insert into hibernate_sequence values ( 1 )
Hibernate: create table t_blog (id bigint not null, appreciation bit not null, commentabled bit not null, content varchar(255), create_time datetime, first_picture varchar(255), flag varchar(255), published bit not null, recommend bit not null, share_statement bit not null, title varchar(255), update_time datetime, views integer, type_id bigint, user_id bigint, primary key (id)) engine=InnoDB
Hibernate: create table t_blog_taglist (bloglist_id bigint not null, taglist_id bigint not null) engine=InnoDB
Hibernate: create table t_comment (id bigint not null, avatar varchar(255), content varchar(255), create_time datetime, email varchar(255), nickname varchar(255), blog_id bigint, parent_comment_id bigint, primary key (id)) engine=InnoDB
Hibernate: create table t_tag (id bigint not null, tag_name varchar(255), primary key (id)) engine=InnoDB
Hibernate: create table t_type (id bigint not null, type_name varchar(255), primary key (id)) engine=InnoDB
Hibernate: create table t_user (id bigint not null, avatar varchar(255), create_time datetime, email varchar(255), nickname varchar(255), password varchar(255), type integer, update_time datetime, username varchar(255), primary key (id)) engine=InnoDB
Hibernate: alter table t_blog add constraint FK292449gwg5yf7ocdlmswv9w4j foreign key (type_id) references t_type (id)
Hibernate: alter table t_blog add constraint FK8ky5rrsxh01nkhctmo7d48p82 foreign key (user_id) references t_user (id)
Hibernate: alter table t_blog_taglist add constraint FK366s4qw9i0ys1gpp80w5pnmmx foreign key (taglist_id) references t_tag (id)
Hibernate: alter table t_blog_taglist add constraint FK6pcs7bqnv1ygvqk4l1qag3tqg foreign key (bloglist_id) references t_blog (id)
Hibernate: alter table t_comment add constraint FKke3uogd04j4jx316m1p51e05u foreign key (blog_id) references t_blog (id)
Hibernate: alter table t_comment add constraint FK4jj284r3pb7japogvo6h72q95 foreign key (parent_comment_id) references t_comment (id)

springboot结合hibernate jpa自动创建数据表