Following are my questions about Spring Data JPA
.
Q1 Is Spring Data JPA, ORM? If not then, what it is?
Q2 What is the advantage of spring data JPA?
Q1 Is Spring Data JPA, ORM? If not then, what it is?
No. It is a system to create "automatic" Data Access Objects (DAOs) for you at compile time, and uses an ORM (like Hibernate) in these DAOs.
Q2 What is the advantage of spring data JPA?
You don't need to write your own DAOs
An example, you create an entity like this:
@Entity
public class Foo {
@Id
private Long id;
private String name;
...
}
and a repository definition like this:
public interface FooRepository extends CrudRepository<Foo, Long> {
//that's it, nothing else. no code
}
Spring Data JPA will then create a real repository class at compile-time that you can use to select, insert, update, and delete your Foo objects.
@Controller
public class FooController {
@Autowired
private FooRepository fooRepository;
@RequestMapping("/")
@ResponseBody
Foo getFoo() {
return fooRepository.findOne(1L); //look, you didn't need to write a DAO!
}
}
This repository class uses your JPA EntityManager at run-time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With