Home - Shubham20015/Sulaah GitHub Wiki

Welcome to the Sulaah wiki!

Learnings while creating this project

  • application.properties

    spring.sql.init.mode=always

    This setting is to tell spring that data is initialized using script files (data.sql or schema.sql). For embedded databases such as H2, this is set to always by default. Or use INSERT IGNORE INTO ... to ignore duplicate error.

    spring.jpa.defer-datasource-initialization=true

    This is used to defer the data initialization after hibernate creates all of the tables. Reference article

  • Spring Annotations

    • @CreationTimestamp:- The @CreationtTimestamp is a convenient annotation that sets the field value to the current timestamp when the entity is first saved.
    • @UpdateTimestamp:- The @UpdateTimestamp is another annotation provided by Hibernate. It automatically sets the field value to the current timestamp on each entity update.
    • @JsonIgnore:- This is required to prevent serialization of child object. As jackson serializer ignores fetchType and uses getters directly to get them.
    • @JoinColumn:- In a One-to-Many/Many-to-One relationship, the owning side is usually defined on the many side of the relationship. It’s usually the side that owns the foreign key.
    • @Transaction:- This annotation is used on a Service to make it a transactional service. This means that any changes made by it will either be complete or none. If anything fails in between then those changes are reverted back to their original state.
  • Why use @joinTable and mappedBy propeties ?

In this article, we looked at the difference between @JoinColumn and mappedBy and how to use them in a one-to-many bidirectional relationship. The @JoinColumn annotation defines the actual physical mapping on the owning side. On the other hand, the referencing side is defined using the mappedBy attribute of the @OneToMany annotation.

Refer to the last two questions also of this ChatGPT conversation