i want perform mysql insert query using hibernate, have this:
string q1="insert sample (datasetstatusid,message,processtime) values('?','?','?') "; query query=session.createsqlquery(q1); query.setparameter(0, 5); query.setparameter(1, "testing"); query.setparameter(2, new date()); int result=query.executeupdate(); tx.commit();
i have following exception occured,
exception in thread "main" org.hibernate.queryparameterexception: position beyond number of declared ordinal parameters. remember ordinal parameters 1-based! position: 1
what's wrong here?
if using hibernate
recommended way save data save()
. hibernate
has methods database operations.but reasons can use native sql
query.saving hibernate
following:
session sess = factory.opensession(); transaction tx; try { tx = sess.begintransaction(); sess.save(yourpojo); tx.commit(); } catch (exception e) { if (tx!=null) tx.rollback(); throw e; } { sess.close(); }
recommended hibernate tutorials:
hibernate reference documentation
hibernate tutorial
Comments
Post a Comment