views:

31

answers:

1

Hi, 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 funtion 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)

Thanks all of you, and sorry about my English.

A: 

I found a solution:

   SQLQuery tempQuery = getSession().createSQLQuery("INSERT INTO TABLA (CAMPO1, CAMPO2) VALUES (valor1, " + "encripta(" + valor2 + ", '" + key + "'))");
   tempQuery.executeUpdate();

Thanks

Michel