使用Hibernate或JPA注释 [英] Hibernate or JPA annotations to use

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

问题描述

我在我们的项目中使用Hibernate,并在Hibernate Domain Pojo Objects的基于注解的配置中使用Hibernate。对于基于注释的配置,我们有两个选项:


  1. 使用 javax.persistence。*

  2. 使用Hibernate Native Annotations org.hibernate.annotations。*

目前我们使用基于JPA的注解配置来处理POJO文件和Hibernate本机API(如SessionFactory,Session等)来打开会话并执行数据库操作。



需要你的帮助,在下面的东西里,


  1. JPA批注并使用Hibernate
    原生API?

  2. link 解释了一个这样的问题
    (cascade-jpa-hibernate-annotation-common-mistake)
  3. 专业知识,使用哪种类型的注释


    1. JPA

    2. Hibernate native




    解决方案

    的JPA实现。如果您在代码中使用纯粹的JPA,那么如果出现需求,您可以自由地更改为不同的实现。例如, EclipseLink / TopLink OpenJPA 是针对不同客户可能需要的实现。一个完整的实现列表是这里



    如果您不得不使用hibernate提供的任何不属于JPA规范的奇特功能,则应该在您的代码库中使用hibernate特定的API。 hibernate论坛此处的相关讨论。


    I am using Hibernate in our projects and annotation based configuration for Hibernate Domain Pojo Objects. For Annotations based configuration we have two options

    1. JPA based annotations using javax.persistence.*
    2. Use Hibernate Native Annotations org.hibernate.annotations.*

    Currently we use JPA based annotation configuration for our POJO files and Hibernate native API like SessionFactory, Session, etc to open session and perform DB operations.

    Need your help in below things,

    1. Is there any problem mixing both JPA annotations and use Hibernate native API?
    2. This link explains one such issue (cascade-jpa-hibernate-annotation-common-mistake)
    3. Please provide your expertise, which type of annotations to use

      1. JPA
      2. Hibernate native
      3. mix both of them?

    解决方案

    Hibernate provides one of the JPA implementations. If you use purely JPA in your code, you are free to change to a different implementation if a requirement arises. For example, EclipseLink/TopLink and OpenJPA are implementations which may be required for a different customer. A comprehensive list of implementations is here.

    If you are compelled to use any exotic features provided by hibernate which are not in JPA specification, you should go for hibernate specific APIs in your code base. A related discussion from hibernate forum here.

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

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