Close

Sequence generation in JPA

@Entity@Table(name = “Facility”)public class FacilityEntity implements Serializable{ private static final long serialVersionUID = -5193920209461702399L; @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = “SEQ_FACILITY_ID”) @SequenceGenerator(name = “SEQ_FACILITY_ID”, sequenceName=”SEQ_FACILITY_ID”) @Column(name=”facilityid”) private Long facilityId;.. } It took me some time to figure this out, you have to have sequenceName in your SequenceGenrator annotation. It might work without it, and might…

Hibernate First Steps

For adding a new object (to database) the code below suffice (you still need to define xml files / JPA annotation still for hibernate configuration): Configuration conf = new Configuration().configure(file);SessionFactory sessionFactory = conf.buildSessionFactory();session =sessionFactory.openSession();//Create new instance of Contact and set values in it by reading them from form object Transaction tx;tx = session.beginTransaction(); System.out.println(“Inserting Record”);contact…