【发布时间】:2022-01-25 16:47:13
【问题描述】:
这是我第一次使用 hibernate,每当我运行项目时,hibernate 都会这样做:
Hibernate: alter table Enseigner add column matiere_reference varchar(255) not null
Hibernate: alter table Enseigner add column professeur_code integer not null
Hibernate: alter table Enseigner add constraint FKbuufx1q63fjcj0h9aaix4cbu3 foreign key (matiere_reference) references matiere (reference)
Hibernate: alter table Enseigner add constraint FKk5idavh0u5pwc1n41h11y7tn3 foreign key (professeur_code) references professeur (code)
Hibernate: select professeur0_.code as code1_2_, professeur0_.login as login2_2_, professeur0_.nom as nom3_2_, professeur0_.pass as pass4_2_, professeur0_.prenom as prenom5_2_ from professeur professeur0_ order by professeur0_.code
(数据库中的字段与java类中的字段类型匹配)
这是数据库
//manyToMany
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">****</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/schoolDB?useSSL=false&serverTimezone=UTC</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.default_schema">eschool</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.show_sql">true</property>
<property name="current_session_context_class">thread</property>
<property name="connection.pool_size">1</property>
<mapping resource="com/Entity/Professeur.hbm.xml"/>
<mapping resource="com/Entity/Matiere.hbm.xml"/>
<mapping resource="com/Entity/Enseigner.hbm.xml"/>
<property name="hibernate.hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>
我正在寻找一种禁用自动创建外键的解决方案
请问我该如何解决这个问题? 提前谢谢你。
【问题讨论】: