【问题标题】:Which java orm that works with spring is the most light weight?哪个与spring一起工作的java orm是最轻量级的?
【发布时间】:2011-11-25 04:43:43
【问题描述】:

我正在构建一个非常简单的 Spring 应用程序。

当涉及到 ORM 时,我不需要任何关系或功能丰富的更改跟踪/会话管理或任何其他花哨的功能。

我只是想要一些映射到我的数据库表的东西,在那里我可以在单个实体上执行基本的 CRUD,例如更新/插入/删除/选择。

我目前正在使用休眠,只是想知道还有什么可以扩展我的知识并简化事情。

【问题讨论】:

标签: java hibernate spring orm


【解决方案1】:

ORM 工具本身并不复杂。事实上,您可能已经注意到,如果使用得当,它们会使开发人员的生活更轻松。您没有提到您在使用 hibernate 时面临哪些问题,这促使您寻找更简单的替代方案。几乎所有ORM tools 都有或多或少相似的功能/API,因为它们从根本上解决了相同的问题。 (Spring支持Hibernate、JDO、iBatis、JPA)

这里是这个论坛上关于休眠使用的非常interesting post。根据经验,如果您的架构具有较少的表(如帖子中提到的 5 - 10 个)并且关系不是很复杂,那么您应该避免使用 ORM 工具,因为这可能是矫枉过正。在这种情况下,JDBC 就足够了。我会强烈推荐spring JDBC(因为您已经在使用spring)。

【讨论】:

    【解决方案2】:

    我不确定我的ORMLite 包是否是“最”轻量级的,但我想我至少会提到它作为一种可能性。它有几个 spring 实用程序类来帮助配置,并且被设计为简单、容易和轻量级。以下是春季文档:

    http://ormlite.com/docs/spring

    这里是手册的getting started section。还有一个spring wiring example可以看看:

    以下是文档中的一些示例 spring 配置:

    <!-- URL used for database, probably should be in properties file -->
    <bean id="databaseUrl" class="java.lang.String">
        <!-- we are using the in-memory H2 database in this example -->
        <constructor-arg index="0" value="jdbc:h2:mem:account" />
    </bean>
    
    <!-- datasource used by ORMLite to connect to the database -->
    <bean id="connectionSource" class="com.j256.ormlite.jdbc.JdbcConnectionSource"
        init-method="initialize">
        <property name="url" ref="databaseUrl" />
        <!-- probably should use system properties for these too -->
        <property name="username" value="foo" />
        <property name="password" value="bar" />
    </bean>
    
    <!-- abstract dao that is common to all defined daos -->
    <bean id="baseDao" abstract="true" init-method="initialize">
        <property name="connectionSource" ref="connectionSource" />
    </bean>
    
    <!-- our daos -->
    <bean id="accountDao" class="com.j256.ormlite.examples.common.AccountDaoImpl"
        parent="baseDao" />
    <bean id="deliveryDao" class="com.j256.ormlite.spring.DaoFactory"
      factory-method="createDao">
        <constructor-arg index="0" ref="connectionSource" />
        <constructor-arg index="1" value="com.j256.ormlite.examples.spring.Delivery" />
    </bean>
    

    【讨论】:

      【解决方案3】:

      我将 MyBatis v3.0.4 与 Spring v3.0 一起使用,效果非常好。我们有很高的性能要求,它能够满足这些要求——嗯,它并没有妨碍我们。如有必要,它也足够灵活,可以处理复杂的事情。只需很少的设置。

      【讨论】:

      • 调用 MyBatis "ORM" 确实是在拉伸它。
      • @skaffman 是的,但考虑到问题的明显动机,这似乎是相关的。 :o)
      猜你喜欢
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 2012-05-02
      • 2010-10-25
      • 2012-06-26
      • 1970-01-01
      相关资源
      最近更新 更多