Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 56 time
Following example show you how to insert using native query in your JPA model .You set the parameter of record using setParameter function . You set the number of the parameter based on its order using question mark (?) .
} /** * @param id * id of the new topic. * @param title * title of the new topic. * @param creationDate * creation date of the topic. */ public void insertTopic(int id,String title,Date creationDate){ Query query = entityManager.createNativeQuery("INSERT INTO topic (ID, TITLE,CREATION_DATE) "+ " VALUES(?,?,?)"); query.setParameter(1, id); query.setParameter(2, title); query.setParameter(3, creationDate); query.executeUpdate(); }