Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write insertinto command in hibernate criteria

I want to write the below InsertInto query in Hibernate Criteria. Any Suggestions .. thanks for help

        sql = "insert into selectedresumes  values('" + companyId + "','"
        + resumeId + "','" + resumeStatusId + "','" + jobId + "')";
like image 724
junaidp Avatar asked Nov 05 '22 20:11

junaidp


1 Answers

Unfortunately, You can't do it.

According to Hibernate documentation

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#batch-direct

Only the INSERT INTO ... SELECT ... form is supported; not the INSERT INTO ... VALUES ... form.

So you just need to create Object and save it using Hibernate and it should look something like that

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Resume selectedresumes  = new Resume();
//set all resume values
session.save(selectedresumes);
tx.commit();
session.close();
like image 197
danny.lesnik Avatar answered Nov 09 '22 10:11

danny.lesnik