Question

For example, these classes:

public class Boss{
    ... 
    @OneToMany(mappedBy="boss")
    Set<Employee> employees;
}

public class Employee{
    @ManyToOne
    Boss boss;
    ...
}

There is a relationship between Boss and Employee. I can find all the employees from a Boss, doing boss.getEmployees().

What does SDFDK do to know the elements of a relationship? Save the id of all employees from a boss?

I would like to know the difference in performance between boss.getEmployees(), and a query with "SELECT e FROM Employee e where e.id='boss_id' "

Thanks.

Was it helpful?

Solution

I would like to know the difference in performance between boss.getEmployees(), and a query with "SELECT e FROM Employee e where e.id='boss_id' "

Difference is yes in performance but works same. JPA is slower than JDBC of course. JDBC is also on lower level than JPA. I tell you this. An usage of ORM has one main advantage and that you will save a lot of time with implementation of your own ORM but you don't have as much control over queries as with if you implement your own ORM. You know nothing about internal implementation of methods and other stuff of JPA.

When you implement your own ORM you have much more control over queries, you can optimize queries based on application requirements but it takes some time. JPA is ORM framework that implements all required db logic instead you. You just need to tell him what you want via annotations.

Next advantage of ORM frameworks is that your application will become independent on database layer(type of datasource) but also you can achieve this by implementation of proper design patterns like AbstractDAOFactory, AbstractDataMapper etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top