Spring Data JPA

better than jdbc !

Configuration

// FOR JPA
spring:
  datasource:
    url: jdbc:postgresql://[host]:[port]/[db name]
    username: username
    password: [password]

  jpa:
   hibernate.ddl-auto: update
   show-sql: true
   properties:
     hibernate:
       dialect: org.hibernate.dialect.PostgreSQLDialect

Embedded

@Embedded
private AnotherClass anotherClass;

// another class

@AttributeOverrides({
		@AttributeOverride(name = "something [in db]", 
		column = @Column(name = "something_field")),
})
public class AnotherClass {
	private String somethingField;
}

OneToOne

OneToMany & ManyToOne

ManyToMany

@Qualifier("")

  • You can mark a component with name, ex : @Component("fakedao") and when performing dependency injection, you can specifies which component to exactly inject, ex : @Qualifier("fakedao")

Repository Interface

Example Repository

Pagination and Sorting Repo

Last updated

Was this helpful?