1.

What are the different Cascade types supported by JPA?

Answer»

JPA annotations are used to map Java persistent CLASSES with their corresponding TABLES in the database. Hibernate is one of the more popular implementations of the JPA specifications. All the JPA annotations are defined in the javax.persistence package. Along with JPA annotations, Hibernate also supports some other annotations which are available in org.hibernate.annotations package. Some of the important annotations are: 

  1. javax.persistence.Entity: This is used with POJO classes to specify that they are entity beans. 
  2. javax.persistence.Table: This is used with entity beans to define the corresponding table name in database. 
  3. javax.persistence.Access: This is used to define the access type, either field or property. Default value is field and if you want hibernate to use getter/setter methods then you need to set it to property. 
  4. javax.persistence.Id: This is used to define the primary key in the entity bean. 
  5. javax.persistence.EmbeddedId: This is used to define composite primary key in the entity bean. 
  6. javax.persistence.COLUMN: This is used to define the column name in database table. 
  7. javax.persistence.GeneratedValue: This is used to define the strategy to be used for generation of primary key. It is used along with javax.persistence.GenerationType enum. 
  8. javax.persistence.OneToOne: This is used to define the one-to-one mapping between two entity beans. Other similar annotations are OneToMany, ManyToOne and MANYTOMANY 
  9. org.hibernate.annotations.Cascade: This is used to define the cascading between two entity beans, used with mappings. It WORKS in conjunction with org.hibernate.annotations.CascadeType 
  10. javax.persistence.PrimaryKeyJoinColumn: This is used to define the property for foreign key. It is used along with org.hibernate.annotations.GenericGenerator and org.hibernate.annotations.Parameter 


Discussion

No Comment Found