I'm writing a native Sql namedQuery, it's insert statement looks like the following:
insert into myTable (
column1,
column2)
values(
'value1'
,'value2' /* value2: is very important */
)
running the above block gives exception: "Error in named query", but when I remove the colon from the comment as following:
insert into myTable (
column1,
column2)
values(
'value1'
,'value2' /* value2 is very important */
)
everything runs fine, any explanation?
EDIT:
I can copy my real statement here but it's really long one. The above is just sample.
Here is the exception stacktrace:
Caused by: org.hibernate.HibernateException: Errors in named queries: insertSalesDocument
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:435)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 194 more
Actually it took me couple of hours to know why I'm getting this exception since my insert statement looks correct and works properly when I copy it to Oracle Sql Developer. It looks to be a bug with hibernate namedQuery parser or something.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…