0

I am working on a Spring boot project where i am using Hibernate as ORM. I have enabled Hibernate Second Level Caching. I have an entity called Country. In country i have a natural Id and i have enabled cache based on Natural ID.

@Entity
@Table(name="t_country")
@Cacheable
@org.hibernate.annotations.Cache(usage="CacheConcurrencyStrategy.READ_WRITE, region="country")
@NaturalIdCache(region="country")
public class Country {
    
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    @Column(name="ID")
    Long id
    
    @NaturalId
    @Column(name="COUNTRY_CODE")
    String countryCode
    .....
    .....
}

When i am querying country using findByCountryCode(String countryCode) method, it is hitting the DB all the time. Can anyone tell me what i am doing wrong here?

Ajay Sankaran
  • 129
  • 1
  • 10

0 Answers0