Hibernate没有创建新表

时间:2017-01-24 20:05:51

标签: mysql hibernate jpa dropwizard

我有下表

@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@Table(name = "School")


@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class School implements  Serializable,  Comparable<School>{

    private static final long serialVersionUID = 1L;


    @JsonProperty
 @JsonProperty
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
long id;

}

这是yaml文件,它将hibernate配置设置为创建新数据库

 charSet: UTF-8
    hibernate.dialect: org.hibernate.dialect.MySQLDialect
    hibernate.hbm2ddl.auto: create
    hibernate.show_sql: true

我读了许多解决类似问题的问题,但我不明白为什么这个表会被hibernate忽略

在尝试不同的解决方案时,似乎只有两个表没有被更新或重新创建。这可能是因为他们之间的关联吗?

这是第二个与之相关的课程

@Entity
@Table(name = "Student")
@SecondaryTable(name = "thirdTable", pkJoinColumns=@PrimaryKeyJoinColumn(name="thirdtablepk_id", referencedColumnName="id"))


@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)


public class Student  implements Comparable<Student>, Serializable {

    private static final long serialVersionUID = 1L;
    @JsonProperty
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    long id;

    @ManyToOne
    School school;
}

1 个答案:

答案 0 :(得分:0)

我猜你使用了

  

hibernate.hbm2ddl.auto:create

创建表后,将不再创建表。为了删除和创建表的时间,您需要使用belwo配置。

  

hibernate.hbm2ddl.auto:create-drop

希望这能解决你的疑问。