在传统世界中需要Hibernate [英] Need for Hibernate in the legacy world

查看:70
本文介绍了在传统世界中需要Hibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个关于休眠的问题。

在很多问题中,有些人认为hibernate对于非常复杂的数据库不是很好的选择。如果我们有非常复杂的数据库,hibernate不是正确的选择。它更适合绿色领域的项目,但对于复杂的遗留数据库来说不太好。


  1. 这是真的吗?

    也是hibernate生成查询。
    每个项目经理都喜欢优化查询(休眠不能生成比sql专家更优化的查询!)。所以对于大型项目来说,聘请sql专家不是问题。 sql专家将优化查询(使用explain sql,使用连接......)

  2. 我的问题是一个庞大而昂贵的项目怎么不关心SQL优化?

    (你会说你可以编写HQL,但正如我在很多文章中看到的那样,解释说HQL并不比sql强大,许多程序员都会头疼,几个小时调整)(你喜欢你身体中的所有器官,理想地工作吗?)
    另外二级缓存有助于休眠很多,因为hibernate知道会产生大量的查询而不是复杂的连接。

  3. 我的问题是:真的是一个复杂的数据库,只能由一个系统修改(例如网站)?如果我们谈论的是企业系统,可以通过多个进程访问数据库,共享不同的编程语言和平台。

    因此,在这种情况下,二级缓存对此帮助不大。


  4. hibernate适合什么样的项目?
    是否适用于没有人关心sql的后台项目?


  5. 当管理员说:请使用memcached进行缓存并请使用这个优化的查询而不是你的?如果您使用的是oracle数据库,orache具有最先进的sql语法。

  6. 他们在非常强大的语法上花费了大量的时间和金钱。如果没有使用该语法,该怎么办。



    该软件只写入一次(然后保留)并使用很长时间。
    如果我是一家订购软件的公司,我会说:我将使用该软件几年,我喜欢快速,如果花费1个月的时间编写休眠软件,我将再支付一个月对于使用IBATIS例子的软件来说,它知道它可以在多年内运行得更好

    (当你购买一辆汽车时,你对汽车经济感兴趣的是1kg油/ km,而不是制造商生产多少汽车!)。所以作为一名软件消费者,我不会对你的生产力感兴趣,只是软件的速度有多快。当然,价格也是相关的,但如果我们谈论价格,就会有更复杂的数学。



    当我们无法预测某些部分系统?

    (如果电流工程师无法预测电流,可以成为一名工程师)

    请分享您的意见。



    Regards

    解决方案


    <1>这是真的?

    不,Hibernate可以处理相当复杂的数据库,包括现有的数据库。但是,它可能无法很好地处理严重非规范化的数据库或异国情调的模式。这是不同的。


    2)(...)我的问题是如何来一个庞大而昂贵的项目不关心SQL优化?

    这是无意义的,使用Hibernate并不意味着你不关心优化。我曾经在一个庞大而复杂的STP系统上工作(数亿美元预算),性能肯定是一个重要的关注点,我们实际上引入了Hibernate以从延迟加载,二级缓存(以及加快开发)等方面受益。

    以下是使用ORM(如Hibernate)时的处理方法(适用时):


    • 使用ORM你会比没有使用ORM更快地完成任务(或者没有任何使用它们的意思)。
    • 绝大多数生成的查询的行为都是正确的(并且事实上,Hibernate比一般开发人员生成的 SQL更好)。

    • 您可以(并且必须)调整查询和Hibernate到一定程度。
      即使您花费一些时间来优化性能(包括下降回到原生SQL查询真正有问题的问题),您仍然可以更快地完成任务。



    <3> (...)所以在这种情况下,二级缓存并没有太大的帮助。


    好吧,你说得对理想情况下使用二级缓存意味着使用Hibernate API(尽管您仍然可以手动驱逐缓存,尽管我倾向于将它用于大部分读取实体)。但是,更重要的是,根据我的经验,通过数据库在许多应用程序之间共享数据只会导致无法维护的应用程序(更改一个位变得不可能,因为它可能影响多个应用程序),应该避免。使用EAI / ESB并通过它公开主系统的服务。这样,您可以重用业务逻辑,二级缓存等。


    4)(...)什么样的冬眠项目适合?对于那些没有人关心sql的后台办公项目吗?

    对于CRUD应用程序来说,Hibernate确实非常好,但不仅如此上面),你的问题显示出我已经说过的一些无知。但是,它不适合任何项目:


    • 我可能不会将它用于数据仓库或大型报告应用程序。 / li>
    • 我可能不会将它用于严重非规范化或异常的遗留数据库(像mybatis这样的数据映射器在这种情况下可能是更好的选择)。
    • 我不会将它与现有的使用存储过程的系统一起使用。

    • 我不会将它用于非RDBMS数据存储:


    $ b


    5)(...)管理员说:请使用memcached进行缓存,请使用此优化查询而不是您的?

    我告诉他memcached可能不是我们上下文中的最佳解决方案(不,我不想总是发送我的数据在线和我不关心Facebook / LiveJournal / Twitter /无论使用它,我们的应用程序可能有不同的需求),在使用Hibernate时还有其他更好的缓存实现,我请他讨论问题和我们讨论各种解决方案等。我们作为一个团队工作,而不是互相攻击。



    总结,ORM解决方案并不总是适用,但我认为您目前有偏见,我的经验与您在问题中表达的意见(不相信)不同。






    I have a several questions about hibernate.

    In many questions here in stackoverflow, several people are saying that hibernate is not a good choise for very complex databases. If we have very complex database, hibernate is not the right choice. It better suits for green field projects, but it is not so good for complex legacy database.

    1. Is this true?
      Also hibernate generates queries. Every project manager will like to have optimized queries (hibernate cannot generate more optimized queries than sql specialist!). So for big project it is not a problem to hire sql specialist. The sql specialist will optimize the queries (use explain sql, use joins ...)

    2. My question is how come a huge and expensive project does not care about sql optimization?
      (you will say that you can write HQL but as I have seen in a lot of posts that explains that HQL is not so powerful than sql and a lot of programmers get headache and several hours of tuning) (you like all your organs in your body to work ideally don't you?) Also the second level cache helps hibernate a lot because hibernate knows to generate a lot of queries instead of complex join.

    3. My question is: Is really a complex db only modified by one system (example the web site)? If we are talking about the enterprise system the db can be accessed via several processes, sharing different programming languages and platforms.
      So in this case the second level cache does not help very much.

    4. For what kind of projects hibernate is suitable for? Is it for back office projects where nobody cares about the sql ?

    5. What happens when your administrator says: please use memcached for caching and please use this optimized queries instead of yours?

    If you are using oracle database, orache has the most advanced sql syntax. They have spend a lot of time and money on the syntax that is very powerful. What for is this syntax if it is not used.

    The software is written only once (and then maintained) and used for a long time. If I am a company that orders software I will say: I will use the software for a couple of years and I like to be fast, and if you spend 1 month for writing software with hibernate I will pay one more month for software that uses example IBATIS knowing that it will work better for years
    (when you are buying a car you are interested in the car economy 1kg-oil/km, not how short and easy the manufacturer produced the car!). So as a software consumer I do not interested in your productivity, just how fast the software is. Of course also the price is relevant but if we are speaking about the price there are more complex mathematics.

    Can we call something engineering when we really cannot predict some part of the system?
    (can electrical engineer be really a engineer if he cannot predict the current)

    Please share your opinion.

    Regards

    解决方案

    1) (...) Is this true?

    No it isn't, Hibernate can deal with pretty complex databases, including existing ones. However, it might not deal very well with an heavily denormalized database or an exotic schema. This is different.

    2) (...) My question is how come a huge and expensive project does not care about sql optimization?

    This is non-sense, using Hibernate doesn't mean you don't care about optimization. I have worked on a huge and complex STP system (several hundreds millions € budget) and performance was definitely an important concern and we actually introduced Hibernate to benefit from things like lazy loading, second level cache (and speed up development).

    Here is the deal when using an ORM like Hibernate (when suitable):

    • You'll be done faster with ORM than without ORM (or there wouldn't be any point at using them).
    • The vast majority of the generated queries will behave correctly (and the fact is that Hibernate generates better SQL than the average developer).
    • You can (and have to) tune queries and Hibernate to a certain degree.
    • Even if you spend some time on performance optimization (including falling back to native SQL for really problematic queries), you'll still be done faster.

    3) (...) So in this case the second level cache does not help very much.

    Well, you are right about the fact that using the second level cache ideally means using Hibernate APIs (although you can still evict the cache "manually" and although I tend to prefer using it for "mostly read" entities). But, more important, to my experience sharing data between many applications through the database just leads to unmaintainable applications (changing a single bit becomes impossible as it may impact several applications) and and should be avoided. Use an EAI/ESB and expose services of the main system through it. This way, you can reuse the business logic, the 2nd level cache, etc.

    4) (...) For what kind of projects hibernate is suitable for? Is it for back office projects where nobody cares about the sql ?

    Hibernate is indeed very nice for CRUD applications, but not only (see above) and your question shows some ignorance as I already said. However, it isn't suitable for any project:

    • I would probably not use it for a data warehouse or a big reporting application.
    • I might not use it with a heavily denormalized or exotic legacy database (a data mapper like mybatis might be a better choice in this case).
    • I might not use it with an existing system using stored procedure for everything.
    • I would not use it with a non RDBMS datastore :)

    5) (...) What happens when your administrator says: please use memcached for caching and please use this optimized queries instead of yours?

    I tell him that memcached is maybe not the best solution in our context (no, I don't want to always send my data over the wire and I don't care that Facebook/LiveJournal/Twitter/whatever are using it, our app might have different needs), there are other better cache implementations when working with Hibernate, I ask him to discuss problems with me and we discuss the various solutions, etc. We work as a team, not against each other.

    To sum up, ORM solutions are not always suitable but I think that you currently have a biased opinion and my experience is different from the opinions (misbeliefs?) expressed in your question.

    See also

    这篇关于在传统世界中需要Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆