简体   繁体   中英

Difference between EclipseLink (non OSGi) vs. EclipseLink JPA

Whats the difference between loading :

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

versus

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

I can seen that Eclipselink named in maven "EclipseLink" has more classes and utilities than the other one...for example target databases:

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

Whats the criteria for using one ore other?

Thank u.

It solely depends on the scope of your requirement. In my case, I had used EclipseLink as suited for my project needs.

One of the main benefits of EclipseLink is that you can call native SQL functions directly in your JPQL queries . In Hibernate this is not directly possible.

Example entity class with named query -

@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;
    }
};

And then set the query parameters, as in the above case we do something like-

 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();
        }

whereas, em is an instance of the entity manager.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM