【问题标题】:Difference between EclipseLink (non OSGi) vs. EclipseLink JPAEclipseLink(非 OSGi)与 EclipseLink JPA 之间的区别
【发布时间】:2016-01-24 14:17:06
【问题描述】:

加载有什么区别:

<dependency org="org.eclipse.persistence" name="eclipselink" rev="2.5.2"/>

对比

<dependency org="org.eclipse.persistence" name="org.eclipse.persistence.jpa" rev="2.5.2"/>

我可以看到在 maven "EclipseLink" 中命名的 Eclipselink 比另一个具有更多的类和实用程序......例如目标数据库:

org.eclipse.persistence.platform.database.oracle.OracleXXXPlatform

使用一种矿石的标准是什么?

谢谢你。

【问题讨论】:

    标签: java eclipse jpa eclipselink


    【解决方案1】:

    这完全取决于您的要求范围。就我而言,我使用 EclipseLink 来满足我的项目需求。

    EclipseLink 的主要优点之一是您可以直接在 JPQL 查询中调用本机 SQL 函数。在 Hibernate 中,这是不可能直接实现的。

    带有命名查询的示例实体类-

    @Entity
    @Table(name = "authorizedUsers", schema = "public")
    
    @NamedQuery(name = "AuthorizedUsers.findByAll",
            query = "SELECT a FROM AuthorizedUsers a where a.username = :username and a.password = :password")
    public class AuthorizedUsers implements Serializable {
        private static final long serialVersionUID = 1L;
    
        @Id
        @Column(name = "id")
        private Integer id;
    
        @Column(name = "username")
        private String username;
    
        @Column(name = "password")
        private String password;
    
        public String getUsername() {
            return username;
        }
    
        public void setUsername(String username) {
            this.username = username;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    };
    

    然后设置查询参数,如上例我们做类似的事情-

     public List<AuthorizedUsers> findFragmentByAll(String username, String password)
                throws PersistenceException, IllegalStateException {
    
            if (em != null) {
                final Query query = em.createNamedQuery("AuthorizedUsers.findByAll");
                query.setParameter("username", username);
                query.setParameter("password", password);
                return query.getResultList();
            }
    

    而 em 是实体管理器的一个实例。

    【讨论】:

      猜你喜欢
      • 2013-09-16
      • 2015-07-08
      • 2023-03-07
      • 2013-10-12
      • 2012-08-16
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-23
      相关资源
      最近更新 更多