db - jdbc vs jpa

DB/Common 2013.09.14 11:31


JPA or JDBC, how are they different?


Layman's terms:

  • JDBC is a standard for Database Access
  • JPA is a standard for OR/M

JDBC is a standard for connecting to a DB directly and running SQL against it - e.g SELECT * FROM USERS, etc. Datasets can be returned which you can handle in your app, and you can do all the usual things like INSERTS, DELETES, run stored procedures, etc. It is one of the underlying technologies behind most java database access (including JPA providers).

One of the issues with traditional JDBC apps is that you can often have some crappy code where lots of mapping between datasets and objects occur, logic is mixed in with SQL, etc.

JPA is a standard for Object Relational Mapping. This is a technology which allows you to map between objects in code and database tables. This can "hide" the SQL from the developer so that all they deal with are java classes, and the provider allows you to save them and load them magically. Mostly, XML mapping files or annotations on getters, setters can be used to tell the JPA provider which fields on your object map to which fields in the DB. The most famous JPA provider is Hibernate, so is a good place to start for concrete examples.

http://www.hibernate.org/

Other examples include OpenJPA, toplink, etc.

Under the hood, hibernate and all the other providers for JPA write SQL and use JDBC to read and write to the DB.


iBatis (nowadays MyBatis) is not an JPA implementation. If you take a look to it, you will notice that it does have very different concept. – Mikko Maunu Aug 9 '12 at 11:30



출처 - http://stackoverflow.com/questions/11881548/jpa-or-jdbc-how-are-they-different

'DB > Common' 카테고리의 다른 글

sql - sql by wiki  (0) 2015.12.14
search - Elasticsearch  (0) 2014.04.24
db - jdbc vs jpa  (0) 2013.09.14
db - ACID  (0) 2013.06.22
Sharding & Query Off Loading  (0) 2013.04.29
SELECT문 순서와 처리순서  (0) 2012.08.29
Posted by linuxism