Skip to content

mohalaoui/e_commerce_shop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Spring data jpa hibernate and postgres

postgres


server.port=7000
spring.datasource.url=jdbc:postgresql://192.168.5.8:5432/dev
spring.datasource.username=vagrant
spring.datasource.password=vagrant
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

hibernate

  • spring config

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update

ehcache

  • enable caching : @EnableCaching(mode = AdviceMode.ASPECTJ)
  • caching entities : @Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "product")
  • spring config

spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
  • ehcache.xml
    • set the default cache policy
    • add custom cache policy by region
  • example:
<defaultCache eternal="false" timeToLiveSeconds="30"
memoryStoreEvictionPolicy="LRU" statistics="true" maxElementsInMemory="10000"
overflowToDisk="false" />

<cache name="product" maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="60" timeToLiveSeconds="60" memoryStoreEvictionPolicy="LRU"
statistics="true">
</cache>

HATEOAS

  • dependency:
<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
  • adding link to resource:
    • ResourceRepresentation that extends RepresentationModel<ResourceRepresentation>
    • adding link: customersRepresentation.add(linkTo(methodOn(ShopControllerImpl.class).getCustomers()).withSelfRel());

About

e_commerce shopping with postgres database design

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages