Annotation of Spring Framework [Java]


In this article, I would like to describe annotation of Spring Framework in Java.

👽 Regarding JPA

@Entity

  • @Entity annotation specifies that the class is an entity.
  • @Entity is a annotation which indicates a managed object of EntityManager.

@id

  • @id applied at the field level to mark the field used for identiy purpose.
@Entity
@IdClass(MyKey.class)
public class YourEntity {
@Id
private int id;
@Id
private int version;
}
public class MyKey implements Serializable {
private int id;
private int version;
}

@Transient

@Transient annotation in JPA is used to indicate that a field is not to be persisted in the database, i.e. their semantics are different.

🐯 @Transactional

Spring’s transaction management @Transactional is generally used when updating/inserting records in multiple tables.

@Service
public class ArticleService {
@Autowired
ArticleDao dao;
// Always start new transaction
@Transactional(propagation=Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
public int create(Artice article) {
return dao.create(article);
}
}

😸 Special Thanks

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!