hibernate注解的实现原理之2

来源:互联网 发布:数据库发展前景ppt 编辑:程序博客网 时间:2024/05/19 08:01

本节核心:以通过注解方式,讲述在数据库内创建对应实体类的映射表的流程。

1.hibernate的实现流程

1.1创建数据库连接

具体创建方式,详见

最常用,最经典,最原始的获取数据库连接的两种方式  

或通过SPRING容器(在applicationContext.xml里边配置数据源)
1.2读取xml配置文件里边,关于hibernate的属性的设置
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
1.3判断处理
hibernate处理程序会根据hibernate.hbm2ddl.auto属性作出对应的处理,如果是hibernate.hbm2ddl.auto=drop-create,刚会通过删除所连接到数据库上所有表,并重新创建;
在生成具体sql创表语句前,会通过注解 原理(

hibernate注解的实现原理之1 

)和反射机制,获取表名,实体名和字段名,属性名,等内容,还会通过hibernate.dialect方言创建相应数据库所支持的SQL创建数据表,最后执行SQL语句。关于其它hibernate属性值,比较简单,在此不讲!

原创粉丝点击