简体   繁体   中英

hibernate doesn't create middle tables with hbm2ddl.auto set to “update”

I was under the impression that when hbm2ddl.auto is set to "update",hibernate(version 3.6) would scan the entity annotations and update database references and create new tables,it has been working fine until today, there are two beans:role and menu,I have defined a unidirectional ManyToMany association for them

@Id
@GenericGenerator(name="uuidGenerator", strategy="uuid")
@GeneratedValue(generator="uuidGenerator")
private String roleId;
@Column
private String roleName;
@ManyToMany(cascade=CascadeType.REMOVE)
@JoinTable( name="roleMenu",
    joinColumns=
        @JoinColumn(name="roleId"),
    inverseJoinColumns=
        @JoinColumn(name="menuid")
        )
private Set<Menu> Menus;

I already have table ROLE and table MENU in the database so I'm expecting hibernate to create the middle table ROLEMENU for me,but it will only try to update the foreign key references in ROLEMENU which results in error cause ROLEMENU doesn't exist yet, but it works fine if I set hbm2ddl.auto to "create", so could someone explain why hibernate doesn't create ROLEMENU before?

It won't.You need to set the option to create or create-drop .

update just does alter table statements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM