As far as I can tell strings containing SQL characters that don't need to be escaped are fine. As soon as a single quote character is introduced the tests fall over - hence the question regarding whether hibernate automatically escapes strings or not.
Here's the details from my previous post:
Hibernate version:
3.1
Spring Framework version:
1.2.7
Full stack trace of any exception that occurs:
Code:
[junit] Testcase: testComments(com.mediagraft.podsplice.dao.hibernate.Hibern
ateCommentaryDAOTest): Caused an ERROR
[junit] Hibernate operation: Could not execute JDBC batch update; bad SQL gr
ammar [insert into comments (username, date, rating, subject, text, comment_id)
values (?, ?, ?, ?, ?, ?)]; nested exception is java.sql.BatchUpdateException: B
atch entry 0 insert into comments (username, date, rating, subject, text, commen
t_id) values (derek_sykes564, 2006-04-28 11:48:47.876000+0100, 3, Average., Not
really the worst thing I've seen but hardly the best. I was really expecting som
ething amazing but in the end was left feeling a little deflated. The chicken in
particular is particularly bad., 1) was aborted. Call getNextException to see
the cause.
[junit] org.springframework.jdbc.BadSqlGrammarException: Hibernate operation
: Could not execute JDBC batch update; bad SQL grammar [insert into comments (us
ername, date, rating, subject, text, comment_id) values (?, ?, ?, ?, ?, ?)]; nes
ted exception is java.sql.BatchUpdateException: Batch entry 0 insert into commen
ts (username, date, rating, subject, text, comment_id) values (derek_sykes564, 2
006-04-28 11:48:47.876000+0100, 3, Average., Not really the worst thing I've see
n but hardly the best. I was really expecting something amazing but in the end w
as left feeling a little deflated. The chicken in particular is particularly bad
., 1) was aborted. Call getNextException to see the cause.
[junit] java.sql.BatchUpdateException: Batch entry 0 insert into comments (u
sername, date, rating, subject, text, comment_id) values (derek_sykes564, 2006-0
4-28 11:48:47.876000+0100, 3, Average., Not really the worst thing I've seen but
hardly the best. I was really expecting something amazing but in the end was le
ft feeling a little deflated. The chicken in particular is particularly bad., 1)
was aborted. Call getNextException to see the cause.
[junit] at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandle
r.handleError(AbstractJdbc2Statement.java:2396)
[junit] at org.postgresql.core.v3.QueryExecutorImpl.processResults(Query
ExecutorImpl.java:1257)
[junit] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecuto
rImpl.java:334)
[junit] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(Abst
ractJdbc2Statement.java:2455)
[junit] at org.apache.commons.dbcp.DelegatingStatement.executeBatch(Dele
gatingStatement.java:294)
[junit] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBat
cher.java:58)
[junit] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatch
er.java:195)
[junit] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.j
ava:235)
[junit] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.j
ava:139)
[junit] at org.hibernate.event.def.AbstractFlushingEventListener.perform
Executions(AbstractFlushingEventListener.java:297)
[junit] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(Def
aultFlushEventListener.java:27)
[junit] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate$29.doInH
ibernate(HibernateTemplate.java:815)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.execute(
HibernateTemplate.java:366)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.flush(Hi
bernateTemplate.java:813)
[junit] at com.mediagraft.podsplice.dao.hibernate.HibernateCommentaryDAO
Test.beforeAssertions(HibernateCommentaryDAOTest.java:63)
[junit] at com.mediagraft.podsplice.dao.hibernate.HibernateCommentaryDAO
Test.testComments(HibernateCommentaryDAOTest.java:1090)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)
[junit] Test com.mediagraft.podsplice.dao.hibernate.HibernateCommentaryDAOTe
st FAILED
Name and version of the database you are using:PostgreSQL 8.1
The generated SQL (show_sql=true):Code:
[junit] Hibernate: select nextval ('comment_id')
[junit] Hibernate: select nextval ('comment_id')
[junit] Hibernate: select nextval ('comment_id')
[junit] Hibernate: insert into comments (username, date, rating, subject, te
xt, comment_id) values (?, ?, ?, ?, ?, ?)
[junit] Hibernate: insert into comments (username, date, rating, subject, te
xt, comment_id) values (?, ?, ?, ?, ?, ?)
[junit] Hibernate: insert into comments (username, date, rating, subject, te
xt, comment_id) values (?, ?, ?, ?, ?, ?)