<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
teddy@DESKTOP-72EP283:/mnt/c/WorkSpace/study/inflearn/inflearn-spring-data-jpa-keesun$ docker run -p 5432:5432 -e POSTGRES_PASSWORD=pass -e POSTGRES_USER=keesun -e POSTGRES_DB=springdata --name postgres_boot -d postgres
16071afa93e33162617a04977345776a664e1d6fbf64078472da61f19e587cc4
teddy@DESKTOP-72EP283:/mnt/c/WorkSpace/study/inflearn/inflearn-spring-data-jpa-keesun$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16071afa93e3 postgres "docker-entrypoint.s…" 6 seconds ago Up 5 seconds 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp postgres_boot
teddy@DESKTOP-72EP283:/mnt/c/WorkSpace/study/inflearn/inflearn-spring-data-jpa-keesun$ docker exec -i -t postgres_boot bash
root@16071afa93e3:/# su - postgres
postgres@16071afa93e3:~$ psql springdata
psql: error: FATAL: role "postgres" does not exist
postgres@16071afa93e3:~$ psql --username keesun --dbname springdata
psql (13.4 (Debian 13.4-1.pgdg100+1))
Type "help" for help.
springdata=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+--------+----------+------------+------------+-------------------
postgres | keesun | UTF8 | en_US.utf8 | en_US.utf8 |
springdata | keesun | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | keesun | UTF8 | en_US.utf8 | en_US.utf8 | =c/keesun +
| | | | | keesun=CTc/keesun
template1 | keesun | UTF8 | en_US.utf8 | en_US.utf8 | =c/keesun +
| | | | | keesun=CTc/keesun
(4 rows)
springdata=# \dt
Did not find any relations.
springdata=# create table account (id int, username varchar(255), password varchar(255));
CREATE TABLE
springdata=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------+-------+--------
public | account | table | keesun
(1 row)
springdata=#
springdata=# select * from account;
id | username | password
----+----------+----------
(0 rows)
@Component
@Transactional
public class AppRunner implements ApplicationRunner {
@PersistenceContext
EntityManager entityManager;
@Override
public void run(ApplicationArguments args) throws Exception {
Account account = new Account();
account.setUsername("keesun");
account.setPassword("jpa");
entityManager.persist(account);
// Hibernate API(ex Session)도 직접 사용 가능함.
Account account1 = new Account();
account1.setUsername("jung");
account1.setPassword("spring");
Session session = entityManager.unwrap(Session.class);
session.save(account1);
}
}