The current code adds a row to the DB. If I reuse this code, it will update the existing row instead of creating a new one. How to create a new row using the same code?
SessionFactory sessionFactory = HibernateFactory.getSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Item item = new Item();
item.setName("name");
item.setPrice(122.3);
item.setCount(225);
session.persist(item);
session.getTransaction().commit();
session.close();
public abstract class AbstractEntity {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name="id")
private Long id;
}
Item extended AbstractEntity