hibernate关联映射(注解) —— 多对一关联关系(@ManyToOne)
hibernate关联映射(注解) —— 一对多关联关系(@OneToMany)
hibernate关联映射(注解) —— 基于外键的双向一对一关联映射(@OneToOne)
hibernate关联映射(注解) —— 基于主键的双向一对一关联映射(@OneToOne)
待续。。。。。。。。。。。。。。。。。。。。。。。。
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/demo_test?characterEncoding=UTF-8</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<!--指定数据库方言 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!--在控制台显示执行的数据库操作语句 -->
<property name="hibernate.show_sql">true</property>
<!--在控制台显示执行的数据库操作语句(格式) -->
<property name="hibernate.format_sql">true</property>
<!--hibernate根据实体自动生成数据库表 -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 配置 CurrentSession -->
<property name="hibernate.current_session_context_class">thread</property>
<!-- 注解配置entity -->
<mapping class="demo.entity.User" />
<mapping class="demo.entity.Group" />
<!-- <mapping class="demo.entity.IdCard" /> -->
</session-factory>
</hibernate-configuration>