Hibernate注释或XML配置 [英] Hibernate annotation or XML configuration

查看:100
本文介绍了Hibernate注释或XML配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Hibernate 开始了一个新项目。 Hibernate的注释是一个更好的选择还是Hibernate的XML映射更好?



我已经使用Hibernate与XML配置,但我不知道注释。
$ b


  1. 在使用基于注解的实现时是否存在任何问题?

  2. 是基于注释的应用程序维护更容易或更复杂?

  3. 哪一个更好(即注释或XML映射),哪一个被广泛使用?为什么?

  4. 如果我在不同级别使用不同的数据库,即生产或集成或开发级别,是否需要更改代码?

注意:我没有比较两种技术,但我想知道在应用程序中使用哪一种(即有两种方式)最新的技术。

解决方案

注释是新应用程序的更好选择,因为它使应用程序免于使用XML文件。它代码少,维护简单。它还有助于重构应用程序(使用IDE,比如Eclipse / NetBeans等),这是XML的问题,因为您需要手动进行更改。



解答:


  1. 没有问题,您可以使用最新的 @Named 而不是 @managedbean ), Spring IoC 图层和Hibernate,这样整个图层你将拥有一个单一的注解概念而不是一个框架特别是。

  2. 维护非常简单,尤其是重构代码,减少或不需要XML文件和新的学习。 Hibernate使用基于JPA的注释。您可以在google中找到一些示例。


  3. 从开始就广泛使用基于XML的应用程序,但是对于新应用程序来说,注释更为成熟。对于任何数据库的更改,代码在注释或XML中将保持不变,只需要更改属性文件值。

  4. / li>


I have started a new project with Hibernate. Is Hibernate annotation a better choice or is Hibernate XML mapping better?

I have used Hibernate with XML configuration, but I have no idea about annotation.

  1. are there any issues while going for annotation based implementation?
  2. is maintenance of an application easier or more complicated with annotation based?
  3. which one is better (that is, annotation or XML mapping) and which one is is widely used? Why?
  4. If I use a different database at a different level, that is, production or integration or development level, do I need to go for change of code?

Note: I am not comparing two technologies, but I want to know which one (that is, out of two ways) to be used in the application with the latest technology.

解决方案

Annotations are a better choice for a new application, since it makes the application free from XML files. It is also less code and maintenance is easy. It also helps for refactoring the application (with IDE like Eclipse/NetBeans, etc.), which is the problem with XML since you need to change it manually.

Answers:

  1. No issues, you can use the latest JSR 330 API (dependency injection for Java) which helps to the same annotation for a JSF managed bean (use @Named instead of @managedbean), the Spring IoC layer and Hibernate, so that whole layer you will have a single annotation concept instead of a framework specific.

  2. Maintenance is easy especially refactoring of code, fewer or no XML files and new learning. Use JPA based annotation with Hibernate. You can find some sample in google.

  3. Widely use XML based since it was there from begining, but for a new application annotation is better which is more mature.

  4. For change to any database, the code will remain the same in annotation or XML, only you need to change the property file values.

这篇关于Hibernate注释或XML配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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