tutorials

Showing posts with label tutorials. Show all posts
Showing posts with label tutorials. Show all posts

The best way to map @OneToOne


@OneToOneThe best approach to bidirectional @OneToOne is to use @MapsIdStudent entity@Entity@Data@Table(name = "students")public class Student implements Serializable {     @Id     @GeneratedValue     private Integer id;     private...

The best way to map @ManyToMany


@ManyToManyMany to many relationships can be easily mapped by creating another table using @JoinTable as follows.Student entity@Data@Table(name = "Student")@Entitypublic class Student implements Serializable {     @Id     @GeneratedValue(strategy = GenerationType.AUTO)...

How to avoid NullPointerException


java.lang.NullPointerExceptionWhen can it be thrown?According to the JavaDoc, the following scenarios can be found.Calling the instance method of a null object.Accessing or modifying the field of a null object.Taking the length of null as if it were an array.Accessing or modifying the slots of null...

States of an object in Hibernate


Hibernate object statesThere are three statesTransient If the object just created, no primary key and not associate with a session, then the object is in the transient statePersistent If a session is open, the object is in the persistent stateDetached If a session is closed, the object...

Streams vs Collections in Java


 Streams vs CollectionsCollectionsStreamsThe collections are used to store & group data in data structures like List, Set, Map...etc.Streams are used to perform complex operations like filtering, matching, mapping, etc... on stored dataData modification can be done. You can add or remove data...

Bean scopes in Spring Framework


Spring Bean scopesSet up the scopeThe @Scope annotation can be used@Scope("singleton")There are 6 scopes are available in the application contextsingleton This is the default scope.The same object is...

Dependency injection in Spring Boot


Dependency injection What is Dependency injection?Dependency injection is a form of the IoC containerIt is just passing dependencies to other objects or frameworks.Dependency injection allows you to...

jar vs war in Spring Boot


 Use jar not warIf you run mvn clean install in Spring Boot, you will get a fat jar file.It contains everything like dependencies, embedded web server... etc.You can just run java -jar jarFile in a JVM, the default is Tomcat embedded server or you can use Jetty.You don't need any web server or...