Posts

Showing posts from March, 2017

How to map many-to-many table relationship with entity without breaking unidirectional many-to-many relationship join table structure?

Image
 You know that join table is necessary to manage the many-to-many relationship. many-to-many relationship can be unidirectional and bidirectional.  After creating entities unidirectional relationship, sometimes middle entity can be necessary to map own entity. According to above mentioned image, our entities should be pre and post as follows. _pre @Entity @Table(name = "role") public class Role { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ROLE_ID", unique = true, nullable = false) private Long id; @Column(name = "name") private String name; //getter and setter } @Entity @Table(name = "user") public class User implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "USER_ID", unique = true, nullable = false) private Long id; @Column(name = "username", nullable = false) private String username; @Column(nam...

JMeter multiple thread group and queue example

Image
 We will  create a JMeter script with multiple thread group.  You can pass  variables from one Thread Group to another with your custom blocking queue. First A thread group will read data from CSV  file and put data into A queue.  B thread group will read the data that thread group  A has put into queue  C  thread group will read the data that thread group B has put into queue.  D  thread group will read the data that thread group C has put into queue. 1) Open JMeter.Right click testplan 2)Adds->Threads->setUP Thread Group. 3)Right click thread group. 4)Add->Sampler->BeanShell Sampler. 5)Now we have 4 thread group and beanshell sampler.(We will write java code in beanshell sampler after create custom queue jar) CREATING CUSTOM JAR 1)Create a class in your IDE.I create a jar from intellij IDE. public class ABlockingQueue { private static LinkedBlockingQueue<Object> q = new LinkedBloc...

Spring data JPA transaction simple Isolation(READ_UNCOMMITTED,READ_COMMITTED,REPEATABLE_READ) example 1.

Image
I create  a test class and write three method. First method will save a new user to database.I started the first method in debug mode and add a debug point in package org.springframework.data.jpa.repository.support.SimpleJPARepository. The  SimpleJPARepository  is the default implementation of Spring Data JPA repository interfaces.  Breakpoint in  save method . this line ( this .em.persist(entity) ).  provides persist of user object public class SimpleJpaRepository<T, ID extends Serializable>  implements JpaRepository<T, ID>, JpaSpecificationExecutor<T> { ... @Transactional public <S extends T> S save(S entity) { if ( this .entityInformation.isNew(entity)) { this .em.persist(entity); //AbstractEntityManagerImpl persist method return entity;// BreakPoint HERE } else { return this .em.merge(entity); } } ..... } Create a test class. @RunWith (SpringJUnit4ClassRu...