字符串字段包含问号

时间:2017-02-15 14:52:58

标签: java hibernate session

当我调用Session.persist传递一个具有多个问号的String属性的实体对象时,我得到如下所示的异常。

异常似乎发生是因为hibernate在预准备语句中使用问号作为值占位符。

有人知道这个问题的解决方法吗?

这里是触发异常的对象的字符串表示:

  

WcmsPart [mpn = 04EAC2 ??? 16-001,cpn = null,description = PRIMER   POLYURETHANE PAINT,数量= 1,......]

以下是例外情况。感谢您的建议

Exception: org.hibernate.exception.ConstraintViolationException: could not execute statement

Stack Trace:
org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:129)
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)
org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3124)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3581)
org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:104)
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
org.hibernate.engine.spi.ActionQueue.executeInserts(ActionQueue.java:337)
org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:176)
org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:216)
org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:334)
org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:289)
org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195)
org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:206)
org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149)
org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)

1 个答案:

答案 0 :(得分:0)

问号应该是Hibernate / SQL中的参数。因此,在保存数据之前,您需要将其转义