轻量级的ORM而不是休眠

编程入门 行业动态 更新时间:2024-10-25 18:32:16
本文介绍了轻量级的ORM而不是休眠 - 强大且敏捷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用了轻量级ORM for j2ee一词,并找到这个页面 http:// java- source/open-source/persistence 来自其中一个结果。我的目标是找到一个比Hibernate更轻的ORM框架,并且还提供了一些对我来说最重要的休眠功能,例如:自动生成表和生成懒惰初始化,并且不会给我表格和地图带来困难。采集。即将到来的ORM在其周围有一个社区也很重要,这使得它能够更快找到错误和错误的解决方案。而且新的orm隐藏我的数据库也很重要(需要更少的sql技能并且更多OO)。 到目前为止,我已经缩小了对iBatis(myBatis)和ORMLite的选择范围。 i希望这个ORM适用于我的新项目,它是j2ee中的一个桌面应用程序,所以重要的是这个orm的启动时间少于其他时间(与Hibernate不同,它首次运行需要很多时间,特别是在运行时你有很多表)

thnx

解决方案

你可能误解了概念。您基本上不会寻找替代Hibernate,而是替代ORM。

Hibernate是适当ORM 的少数尝试之一。 。 Hibernate试图解决大部分对象/关系不匹配的范例。这些是:

    <粒度问题
  • 子类型问题
  • 身份问题
  • 与关联相关的问题
  • 数据导航问题

有关更多信息,请参见 Java Persistence with Hibernate 。

综上所述,没有轻量级的ORM。有适当的ORM解决方案或其他解决方案(如myBatis),而不是将关系模型映射到对象模型,则将SQL语句映射到对象和方法。

别忘了 - 你不必使用所有的Hibernate特性。您可以非常舒适地将其与自定义SQL,纯JDBC并仅使用其功能的子集混合使用。

edit1:关于启动速度缓慢

Intermezzo :我目前正在使用一种专门为我们的应用程序进行调整的专有ORM解决方案(不像Hibernate那样聪明)。最大的问题还在于启动,这是因为将整个数据库映射到对象根本不是微不足道的。

现在和Hibernate一样。也许你知道,Hibernate在启动时也会生成CRUD SQL语句。如果你有大数据库,这可能会影响性能。但是,您可以关闭此启动SQL生成并将切换到运行时生成的动态语句。

使用XML表示法,可以这样实现:

< class name =SomeClass dynamic-insert =true dynamic-update =true> ... < / class>

或者使用Hibernate注释: <$ p $ @Entity @ org.hibernate.annotations.Entity( dynamicInsert = true,dynamicUpdate = true ) public class SomeClass {...

edit2:关于混合自定义SQL

参考书籍Java Persistence with Hibernate深入解释了一些事情。第8章介绍如何使用遗留数据库,并提供如何更改DML(如使用自定义SQL,甚至可以用自定义SQL替换CRUD代码!)和DDL(通用运行时DDL操作)。你应该偷看:)

i googled the phrase "lightweight ORM for j2ee" and find this page java-source/open-source/persistence from one of results. my goal is to find an ORM Framework that is lighter than Hibernate and also delivers some of hibernates features that are most important to me, for example: auto table generating and lazy initializing, and don't give me hard time with tables and maps and collection. it is also important that the coming ORM has a community around it which makes it faster to find solutions to errors and bugs. and it also is important that the new orm hides the database from me (needs less sql skills and be more OO). so far i have narrowed my choices to iBatis (myBatis) and ORMLite. i want this ORM for my new project which is a desktop application in j2ee, so it is important that the start up time for this orm be less than others (unlike Hibernate which takes a lot of time for first time running specially when you have lots of tables)

thnx

解决方案

I am afraid that you might have misunderstood concepts. You basically aren't looking for alternative to Hibernate, but an alternative to ORM.

Hibernate is one of the very few attempts of proper ORM. Hibernate tries to solve most of of paradigms of object/relational mismatch. Those are:

  • problem of granularity
  • problem of subtypes
  • problem of identity
  • problems relating to associations
  • problem of data navigation

See Java Persistence with Hibernate for more information.

To sum up, there is no such thing as lighter ORM. There is either proper ORM solution, or other solutions - like myBatis, where instead of mapping relational model to object model you map SQL statements to objects and methods.

And don't forget - you don't have to use all of Hibernate features. You can quite comfortably mix it with custom SQL, plain JDBC and use only subset of it's capabilities.

edit1: about slow startup

Intermezzo: I am currently working with one propietary ORM solution (not as smart as Hibernate tough) whitch was tuned specially for our application. The biggest issue is also startup, that's becuase mapping the whole database to objects simply isn't trivial.

Now, as for Hibernate. Maybe you know, that Hibernate also generates CRUD SQL statements on startup. If you have big database this can impact performance. But, you can turn off this startup SQL generation and switch to dynamic statements generated at runtime.

Using XML notation, it can be achieved like this:

<class name="SomeClass" dynamic-insert="true" dynamic-update="true"> ... </class>

Or with Hibernate annotations:

@Entity @org.hibernate.annotations.Entity( dynamicInsert = true, dynamicUpdate = true ) public class SomeClass { ...

edit2: about mixing custom SQL

The referenced book Java Persistence with Hibernate explains things rather in depth. Chapter 8 is about working with legacy databases and it also gives hints how to alter DML (like with custom SQL, you can even replace CRUD code with custom SQL!) and DDL(generic runtime DDL manipulation). You should peek there :)

更多推荐

轻量级的ORM而不是休眠

本文发布于:2023-07-17 06:48:34,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是   ORM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!