`
dylan_cherie
  • 浏览: 17296 次
  • 性别: Icon_minigender_1
最近访客 更多访客>>
社区版块
存档分类
最新评论

Spring下使用Hibenrate annotation

阅读更多
xml 代码
  1. <bean id="sessionFactory"  
  2.     class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  3.     <property name="configurationClass">  
  4.         <value>org.hibernate.cfg.AnnotationConfiguration</value>  
  5.     </property>  
  6.     <property name="configLocation">  
  7.         <value>classpath:hibernate.cfg.xml</value>  
  8.     </property>  
  9. </bean>  


 

LocalSessionFactoryBean 中的原码注解:

 

private Class configurationClass = Configuration.class;

 /**
  * Specify the Hibernate Configuration class to use.
  * Default is "org.hibernate.cfg.Configuration"; any subclass of
  * this default Hibernate Configuration class can be specified.
  *

Can be set to "org.hibernate.cfg.AnnotationConfiguration" for
  * using Hibernate3 annotation support (initially only available as
  * alpha download separate from the main Hibernate3 distribution).
  *

Annotated packages and annotated classes can be specified via the
  * corresponding tags in "hibernate.cfg.xml" then, so this will usually
  * be combined with a "configLocation" property that points at such a
  * standard Hibernate configuration file.
  * @see #setConfigLocation
  * @see org.hibernate.cfg.Configuration
  * @see org.hibernate.cfg.AnnotationConfiguration
  */
 public void setConfigurationClass(Class configurationClass) {
  if (configurationClass == null || !Configuration.class.isAssignableFrom(configurationClass)) {
   throw new IllegalArgumentException(
     "configurationClass must be assignable to [org.hibernate.cfg.Configuration]");
  }
  this.configurationClass = configurationClass;
 }

分享到:
评论
5 楼 dylan_cherie 2006-12-30  
    不好意思没说明白,此文讲的是Hibenrate annotation在spring中使用的配置方法。
4 楼 温柔一刀 2006-12-24  
楼主估计是想说Spring下使用Hibenrate annotation时sessionFactory的配置
3 楼 ahuaxuan 2006-12-24  
lz说话相当的言简意赅,我也是没有弄懂楼主的目的,楼主能否更详细点来描述一下:你要做什么,怎么做,为什么要这么做?
2 楼 daoger 2006-12-22  
<br/>
<strong>dylan_cherie 写道:</strong><br/>
<div class='quote_div'><font>
<div class='code_title'>xml 代码</div>
</font><div class='dp-highlighter'><font>
<div class='bar'>
<ol class='dp-xml'>
    <li class='alt'><span><span class='tag'>&lt;</span><span class='tag-name'>bean</span><span> </span><span class='attribute'>id</span><span>=</span><span class='attribute-value'>"sessionFactory"</span><span>  </span></span> </li>
    <li class=''><span>    </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"org.springframework.orm.hibernate3.LocalSessionFactoryBean"</span><span class='tag'>&gt;</span><span>  </span> </li>
    <li class='alt'><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"configurationClass"</span><span class='tag'>&gt;</span><span>  </span> </li>
    <li class=''><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>value</span><span class='tag'>&gt;</span><span>org.hibernate.cfg.AnnotationConfiguration</span><span class='tag'><span class='tag-name'>value</span><span class='tag'>&gt;</span><span>  </span> </span></li>
    <li class='alt'><span>    </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
    <li class=''><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"configLocation"</span><span class='tag'>&gt;</span><span>  </span> </li>
    <li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>value</span><span class='tag'>&gt;</span><span>classpath:hibernate.cfg.xml</span><span class='tag'><span class='tag-name'>value</span><span class='tag'>&gt;</span><span>  </span> </span></li>
    <li class=''><span>    </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
    <li class='alt'><span><span class='tag'><span class='tag-name'>bean</span><span class='tag'>&gt;</span><span>  </span> </span></span></li>
</ol>
</div>
<p><br/>
 </p>
<p>LocalSessionFactoryBean 中的原码注解:</p>
<p> </p>
<p><font>private Class configurationClass = Configuration.class;</font></p>
<p><font> /**<br/>
  * Specify the Hibernate Configuration class to use.<br/>
  * Default is "org.hibernate.cfg.Configuration"; any subclass of<br/>
  * this default Hibernate Configuration class can be specified.<br/>
  * </font></p>
<p>Can be set to "org.hibernate.cfg.AnnotationConfiguration" for<br/>
  * using Hibernate3 annotation support (initially only available as<br/>
  * alpha download separate from the main Hibernate3 distribution).<br/>
  * </p>
<p>Annotated packages and annotated classes can be specified via the<br/>
  * corresponding tags in "hibernate.cfg.xml" then, so this will usually<br/>
  * be combined with a "configLocation" property that points at such a<br/>
  * standard Hibernate configuration file.<br/>
  * @see #setConfigLocation<br/>
  * @see org.hibernate.cfg.Configuration<br/>
  * @see org.hibernate.cfg.AnnotationConfiguration<br/>
  */<br/>
 public void setConfigurationClass(Class configurationClass) {<br/>
  if (configurationClass == null || !Configuration.class.isAssignableFrom(configurationClass)) {<br/>
   throw new IllegalArgumentException(<br/>
     "configurationClass must be assignable to [org.hibernate.cfg.Configuration]");<br/>
  }<br/>
  this.configurationClass = configurationClass;<br/>
 }</p>
</font></div>
<br/>
<br/>
没弄懂lz要干什么!<br/>
<br/></div>
1 楼 shaucle 2006-12-22  
学习一下

相关推荐

    Hibenrate之多对多关联

    默认情况下,Hibernate采用懒加载策略,只有在实际访问集合属性时才会去查询数据库。如果希望在加载实体时同时加载关联的集合,可以使用`@Fetch(FetchMode.JOIN)`或在查询时使用`JOIN FETCH`。 总的来说,Hibernate...

    hibernate struts2 spring

    在这种模式下,Spring作为整体架构的基石,负责管理应用的生命周期和组件依赖;Struts2作为前端控制器,处理HTTP请求并调用业务逻辑;Hibernate则处理数据持久化,将Java对象与数据库记录进行映射。这种集成方式使得...

    图书馆之春:您可以在其中借书的图书馆Web应用程序。 这是Spring MVC和Hibernate项目

    数据库和配置MySQL 飞路(用于数据迁移) GradleTomcat吉特Google Book API 后端技术JavaSpring MVC,Spring AOP,Spring Security Hibernate ORM,Hibernate Validator,Hibenrate Search(Lucene) 翻新,JSON ...

    Hibernate更新某些字段

    在使用 Annotation 配置时,我们可以使用 @Column(updatable=false) 注解来设置某些属性的更新权限。例如,我们可以设置 age 属性的更新权限为 false: ```java @Column(updatable=false) public int getAge() { ...

    公交车查询系统,公交车查询系统

    公交车查询系统是一款基于Java技术栈,利用Spring框架和Hibernate ORM工具构建的Web应用程序,旨在为用户提供方便快捷的公交线路、站点及时刻查询服务。在这个系统中,用户可以通过输入公交线路号或者站点名称,获取...

    hibernatewuwei

    hibenrate的代码本人的培训的代码,老师讲解的很好。是一个学习hibenrate的好的工具

    hibernate学习资料

    hibernahibernate学习资料te学习资料hibernate学习资料v

Global site tag (gtag.js) - Google Analytics