Noor
Noor

Reputation: 20130

Hibernate Insert Query in Java

Can anyone tell me how to perform an insert query with Hibernate and back end postgresql I am using the following implementation but not working

Session session = gileadHibernateUtil.getSessionFactory().openSession();
session.beginTransaction();

User A= new User();
A.setId(67);
A.setFirstName("Noor");
A.setLastName("asd");
A.setMobileNumber("2435");
A.setTelephoneNumber("dfg");

session.save(A);
session.getTransaction().commit();

Upvotes: 1

Views: 2484

Answers (1)

Mike Cialowicz
Mike Cialowicz

Reputation: 10020

As Matt Ball suggested, try using EntityManager.persist(java.lang.Object entity) (see here) instead. Or simply try using persist without EntityManager (see this discussion).

Upvotes: 1

Related Questions