I write this post to know if someone knows how to do this:
I want to do this insert:
INSERT INTO TABLA (CAMPO1, CAMPO2) VALUES (?, crypt(?,'cdp'))
Crypt is a function stored in my database and the insert I would want to do it in my code. Actually when I want to insert something in the database I use:
getHibernateTemplate().persist(obj);
But I want to do a "custom" insert, because I need to use that function.
I am using hibernate + annotations:
@org.hibernate.annotations.SQLInsert (sql = "INSERT INTO TABLA (CAMPO1, CAMPO2) VALUES (?, crypt(?,'cdp'))")
But the key 'cdp' must be readed from a file, so this solution doesn't work for me.
I want to use a method on my code to execute a SQL query (INSERT query)
Here's a solution:
Query query = getSession().createSQLQuery("INSERT INTO TABLA (CAMPO1, CAMPO2) VALUES (:valor1, encripta(:valor2, :key))");
query.setParameter("valor1", valor1);
query.setParameter("valor2", valor2);
query.setParameter("key", key);
query.executeUpdate();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With