Jimmer: 一个面向Java和Kotlin的革命性ORM

本文探讨了OLTP项目中数据库操作的场景,分析了传统ORM(如JPA)和DTOMapper(如MyBatis)的优缺点。Jimmer作为一种新型解决方案,结合两者长处,提供动态实体和任意复杂数据结构的查询与修改能力,同时具备强大的缓存机制和SQLDSL。它解决了传统ORM属性级裁剪不足和DTO类型膨胀的问题,实现了更高效的数据交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 本文的讨论前提

OLTP类型项目很大一部分操作是都针对数据库原始数据,这时软件系统中的对象结构和数据库的中数据结构大体一致,是本文讨论的场景。

而因业务计算而引入的计算指标相关的数据类型,和数据库的原始结构并不相同,并非本文的讨论范场景。

2. 现有技术流派的缺陷

现在,用户访问关系型数据库的框架很多,总体上分为两个派别

  • 传统ORM派,以JPA, Exposed, Ktorm为代表。
  • DTO Mapper派,以MyBatis, JOOQ为代表。

以上两派都有各自的优缺点,Jimmer完美融合两派之长,走出了截然不同的第三条路。因此并不能比把Jimmer上述两个派中的任何方案做简单对比。

2.1. 以JPA为代表的传统ORM派

在传统ORM中,开发人员创建实体类,和数据库表结构直接对应。从映射的角度讲,非常简单。

传统ORM注重维护对象之间的关系,以JPA为例

List<Book> books = entityManager
    .createQuery(
        "select book from Book book " +
        "left join fetch book.store " +
        "left join fetch book.authors"
    ).getResultList();
复制代码

这个例子中的join fetch是JPA的一个特色功能,可以利用SQL JOIN使返回的Book对象不再是孤单对象,而是附带了关联属性store

### Jimmer ORM Framework Usage and Documentation #### Introduction to Jimmer ORM Jimmer is a revolutionary Object-Relational Mapping (ORM) framework designed specifically for Java and Kotlin developers. This framework aims at enhancing the efficiency of database interactions by providing an intuitive API that simplifies common tasks such as querying, updating, inserting, and deleting records from relational databases[^2]. #### Key Features of Jimmer ORM One significant advantage of using Jimmer lies in its performance optimizations. Unlike many other ORMs which rely heavily on Java reflection mechanisms, Jimmer avoids this approach entirely, leading to superior execution speed when compared against popular alternatives like MyBatis or Hibernate[^3]. To achieve high performance without sacrificing ease-of-use, Jimmer incorporates several advanced features: - **Non-reflection-based design**: By eliminating reliance upon Java's built-in reflection capabilities. - **Efficient query generation**: Automatically generates optimized SQL queries based on user input. #### Basic Setup and Configuration Before diving into specific functionalities offered by Jimmer, it’s important first set up your project correctly according to official guidelines provided within the tutorial document[^1]: ```bash # Clone repository git clone https://gitcode.com/gh_mirrors/ji/jimmer.git # Navigate inside cloned directory cd jimmer # Build with Maven mvn clean install ``` After setting up successfully, one can start exploring various aspects covered under "Basic Concepts", including entity mapping rules, session management practices, transaction handling strategies etc., all explained thoroughly through practical examples given throughout the guidebook. #### Advanced Topics: Fetching Specific Fields Without DTOs Using `Fetchr` For scenarios where only certain fields need retrieving but creating new Data Transfer Objects (DTOs) seems unnecessary overhead; Jimmer offers another solution called 'Fetchr'. It allows specifying exactly what data should be fetched directly during runtime while maintaining type safety across application layers[^4]. Example demonstrating how to fetch selected columns: ```java // Assume we have an Entity class named User List<User> users = db.from(User.class).fetch(new Fetchr() {{ addField("id"); addField("name"); }}); ``` This code snippet shows fetching just two properties (`id`, `name`) out of potentially more available ones defined inside `User` model definition file. --related questions-- 1. How does Jimmer compare in terms of performance benchmarks versus traditional ORM frameworks? 2. Can you provide detailed steps about integrating Jimmer into existing Spring Boot applications? 3. What are some best practices recommended when working with transactions using Jimmer? 4. Is there any support for batch operations within Jimmer? If yes, could you give brief instructions? 5. Are there plans to extend compatibility beyond MySQL and PostgreSQL databases currently supported by Jimmer?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值