`
princex
  • 浏览: 6178 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

hibernate的初始配置

阅读更多
This is an example of a typical Hibernate startup procedure, in one line of code,
using automatic configuration file detection:
SessionFactory sessionFactory =
new Configuration().configure().buildSessionFactory();
Wait—how did Hibernate know where the configuration file was located and
which one to load?
When new Configuration() is called, Hibernate searches for a file named
hibernate.properties in the root of the classpath. If it’s found, all hibernate.*
properties are loaded and added to the Configuration object.
When configure() is called, Hibernate searches for a file named hibernate.
cfg.xml in the root of the classpath, and an exception is thrown if it can’t
be found. You don’t have to call this method if you don’t have this configuration
file, of course. If settings in the XML configuration file are duplicates of properties
set earlier, the XML settings override the previous ones.


--
Hibernate logs all interesting events through Apache commons-logging, a thin
abstraction layer that directs output to either Apache Log4j (if you put log4j.jar in
your classpath) or JDK 1.4 logging (if you’re running under JDK 1.4 or above and
Log4j isn’t present). We recommend Log4j because it’s more mature, more popular,
and under more active development.
分享到:
评论

相关推荐

    hibernate配置文件详解

    Hibernate 配置文件详解 Hibernate 是一个流行的 ORM(Object-Relational Mapping)框架,用于简化 Java 应用程序中的数据库交互。 Hibernate 的配置文件是其核心组件之一,用于定义 Hibernate 的运行期参数。下面...

    Hibernate Search配置及简单应用

    这通常在Hibernate的配置类或初始化代码中完成: ```java StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder(configuration); serviceRegistryBuilder.applySetting(...

    JAVA 使用hibernate配置实例

    4. 初始化SessionFactory:在代码中通过Configuration类加载配置文件,然后创建SessionFactory对象。 5. 使用Session:通过SessionFactory获取Session对象,进行数据操作。 对于Maven工程,配置过程有所不同: 1....

    hibernate的配置使用和各种查询

    #### 二、Hibernate初始化 ##### 1. 获取SessionFactory实例 - **通过Configuration实例** - 配置文件(通常为`hibernate.cfg.xml`)包含了数据库连接等信息。 - 使用`Configuration`类加载这些配置信息,并创建...

    hibernate--5.Hibernate配置文件详解-2

    通常,Hibernate的配置文件以`hibernate.cfg.xml`的形式存在,它是项目初始化和连接数据库的关键。 首先,配置文件会定义数据源,包括数据库URL、用户名和密码。例如: ```xml <property name="hibernate....

    hibernate--5.Hibernate配置文件详解

    压缩包中的`0000.sql`可能是数据库脚本文件,用于初始化数据库结构,而`hibernate-2`可能是另一个相关的文件或目录,可能包含了更多的配置示例或实体类定义。在实际开发中,我们需要结合这些资源来构建完整的...

    Eclipse中Hibernate简单配置和使用

    SessionFactory接口负责初始化Hibernate。它充当数据存储源的代理,并负责创建Session对象。这里用到了工厂模式。需要注意的是SessionFactory并不是轻量级的,因为一般情况下,一个项目通常只需要一个SessionFactory...

    Hibernate配置文件加载后修改配置信息

    这样,在Hibernate启动时,就会使用我们的自定义类来初始化数据库连接。 ##### 3. 利用反射修改配置 通过反射机制,我们可以获取到`Environment`类中的属性,进而修改`Properties`对象中的配置信息。具体实现方式...

    Hibernate配置

    在使用Hibernate之前,首先需要在项目的`hibernate.cfg.xml`配置文件中进行初始化设置。此文件包含了数据库连接信息、JDBC驱动类、事务管理器等关键参数。例如: ```xml <hibernate-configuration> <!-- 数据库...

    myeclipse+hibernate项目配置包

    - **SessionFactory配置**: 在项目中初始化SessionFactory,这是Hibernate的核心,用于创建Session实例,处理数据库交互。 - **测试连接与操作**: 编写测试类,验证Hibernate配置是否正确,如查询、插入、更新和...

    hibernate_esb配置

    2. **直接调用Hibernate API**:在ESB服务中直接引用Hibernate库,然后在服务逻辑中初始化SessionFactory并进行数据库操作。这种方式需要对Hibernate有深入的理解,并且可能导致服务与数据库的耦合度增加。 在ESB...

    Hibernate4 jar包及配置文件

    通过加载hibernate.cfg.xml配置文件,我们可以初始化SessionFactory。 此外,了解Criteria查询、HQL(Hibernate Query Language)和命名查询也是必要的。这些查询语言提供了更高级别的抽象,使得我们可以在不写SQL...

    hibernate+spring配置详细解析

    ### Hibernate与Spring集成配置详解 #### 一、概述 在现代Java企业级应用开发中,Hibernate作为一款流行的ORM(对象关系映射)框架,能够极大简化数据库操作;而Spring作为一个全面的企业级应用开发框架,提供了...

    hibernate基本配置要用到的包

    在Java应用中,通常通过`SessionFactory`来初始化Hibernate,然后使用`Session`进行数据库操作。 请注意,上述列表可能根据你的具体需求和Hibernate版本有所不同。确保从官方或可靠的源获取并匹配相应的版本,以...

    Spring+Struts+Hibernate比较详细的整合配置方案

    - 配置`web.xml`,添加Struts和Spring的初始化参数和过滤器。 - 在Spring的配置文件中,使用`<bean>`标签实例化Action类,并注入依赖的服务和DAO。 - 在Struts的`struts-config.xml`中,配置Action和Action...

    hibernate同时配置多个数据库连接

    - **初始化SessionFactory**:在代码中,需要根据配置文件创建对应的`SessionFactory`对象,例如`SessionFactory db1SessionFactory = new Configuration().configure("db1.cfg.xml").buildSessionFactory();...

    SpringMVC+Hibernate5 项目配置Demo

    - **web.xml**:配置DispatcherServlet,定义其初始化参数,如servlet-name、url-pattern等。 - **spring-mvc-config.xml**:SpringMVC的核心配置文件,包括视图解析器、拦截器、bean定义等。 - **Model-View-...

    Hibernate与常用连接池的配置

    **标题:“Hibernate与常用连接池的配置”** 在Java企业级开发中,数据库连接管理是一项至关重要的任务。Hibernate作为一款强大的对象关系映射(ORM)框架,极大地简化了数据库操作。然而,为了优化数据库资源的...

    hibernate的配置视频

    《Hibernate配置详解》 在Java世界中,Hibernate作为一款强大的对象关系映射(ORM)框架,极大地简化了数据库操作。本教程将通过一系列视频深入探讨Hibernate的配置过程,旨在帮助开发者快速掌握其核心配置和使用...

    Eclipse Hibernate基本配置及简单实现

    1. **SessionFactory初始化**: 使用Hibernate的Configuration类读取配置文件,并生成SessionFactory。 ```java Configuration config = new Configuration().configure("hibernate.cfg.xml"); SessionFactory ...

Global site tag (gtag.js) - Google Analytics