2013年9月16日星期一

Encountered a strange problem : The column name Attr

Today use hibernate execute a search method when the table when the report a mistake . Error codes are as follows :
The column name creation_date_by_system is not valid.

org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException (SQLStateConverter.java: 103)
at org.hibernate.exception.SQLStateConverter.convert (SQLStateConverter.java: 91)
at org.hibernate.exception.JDBCExceptionHelper.convert (JDBCExceptionHelper.java: 43)
at org.hibernate.loader.Loader.doList (Loader.java: 2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache (Loader.java: 2104)
at org.hibernate.loader.Loader.list (Loader.java: 2099)
at org.hibernate.loader.custom.CustomLoader.list (CustomLoader.java: 289)
at org.hibernate.impl.SessionImpl.listCustomQuery (SessionImpl.java: 1695)
at org.hibernate.impl.AbstractSessionImpl.list (AbstractSessionImpl.java: 142)
at org.hibernate.impl.SQLQueryImpl.list (SQLQueryImpl.java: 152)
at com.sml.eplatform.admin.dao.HelpFileDaoHibernate.getHelpFile (HelpFileDaoHibernate.java: 195)
at com.sml.eplatform.admin.service.AdminServiceImpl.getHelpFile (AdminServiceImpl.java: 4308)
at com.sml.eplatform.admin.ui.action.SearchHelpFileAction.execute (SearchHelpFileAction.java: 76)
at org.apache.struts.action.RequestProcessor.processActionPerform (RequestProcessor.java: 425)
at org.apache.struts.action.RequestProcessor.process (RequestProcessor.java: 228)
at org.apache.struts.action.ActionServlet.process (ActionServlet.java: 1913)
at org.apache.struts.action.ActionServlet.doPost (ActionServlet.java: 462)
at javax.servlet.http.HttpServlet.service (HttpServlet.java: 643)
at javax.servlet.http.HttpServlet.service (HttpServlet.java: 723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java: 290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java: 206)
at com.sml.eplatform.app.LoginSecurityFilter.doFilter (LoginSecurityFilter.java: 71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java: 235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java: 206)
at com.sml.eplatform.app.EncodingFilter.doFilter (EncodingFilter.java: 32)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java: 235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java: 206)
at org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java: 233)
at org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java: 191)
at org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java: 127)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 103)
at org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java: 109)
at org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java: 293)
at org.apache.coyote.http11.Http11Processor.process (Http11Processor.java: 861)
at org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process (Http11Protocol.java: 606)
at org.apache.tomcat.util.net.JIoEndpoint $ Worker.run (JIoEndpoint.java: 489)
at java.lang.Thread.run (Unknown Source)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The column name creation_date_by_system is not valid.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError (Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn (Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getTimestamp (Unknown Source)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getTimestamp (DelegatingResultSet.java: 300)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getTimestamp (DelegatingResultSet.java: 300)
at org.hibernate.type.CalendarType.get (CalendarType.java: 30)
at org.hibernate.type.NullableType.nullSafeGet (NullableType.java: 163)
at org.hibernate.type.NullableType.nullSafeGet (NullableType.java: 154)
at org.hibernate.type.AbstractType.hydrate (AbstractType.java: 81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate (AbstractEntityPersister.java: 2096)
at org.hibernate.loader.Loader.loadFromResultSet (Loader.java: 1380)
at org.hibernate.loader.Loader.instanceNotYetLoaded (Loader.java: 1308)
at org.hibernate.loader.Loader.getRow (Loader.java: 1206)
at org.hibernate.loader.Loader.getRowFromResultSet (Loader.java: 580)
at org.hibernate.loader.Loader.doQuery (Loader.java: 701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections (Loader.java: 236)
at org.hibernate.loader.Loader.doList (Loader.java: 2220)
... 33 more
Sep 13, 2013 6:31:22 PM org.apache.catalina.core.ApplicationContext log
INFO: com.sml.eplatform.base.ApplicationServiceException: get HelpFile Error

cause from my database in sql servre added a new field . creation_date_by_system, then the entity class has increased in the field of set and get methods .

public Calendar getCreationDateBySystem() {
return creationDateBySystem;
}
public void setCreationDateBySystem(Calendar creationDateBySystem) {
this.creationDateBySystem = creationDateBySystem;
}


in the mapping file is also equipped with the corresponding attributes:

<property name="creationDateBySystem" type="calendar">
    <column name="creation_date_by_system"/>
  </property>
<property name="lastUpdatedDateBySystem" type="calendar">
    <column name="last_updated_date_by_system"/>
  </property>


In the absence of this field before the newly added , the table also has a similar type datetime fields. Configuration is the same. Did not increase in this field can be queried before that get results ! Add this field , they reported this wrong. the network did not seem to find the corresponding answer.

There is no god exists !
------ Solution ---------------------------------------- ----
description and code from your point of view, there should be no mistake
I think you should first check the database you add the column with no effect
For example, you can first use pure JDBC way to run a new add that column with the Query
------ Solution ----------------- ---------------------------
put the hibernate showsql open and see what sql wrong
----- - Solution --------------------------------------------
hibernate Calendar class does not correspond to the database attribute type , right ? Changed to use Date try, is java.util.Date, not java.sql.Date.
------ For reference only -------------------------------------- -
sorry, but a little better this week , so forget coming back up . Forgot to say, print out the sql execution in sql server which is no problem . You can get the result I wanted !
------ For reference only -------------------------------------- -
already in effect . Because I used to print out on the console to the database inside sql execution , you can find the data I need .
------ For reference only -------------------------------------- -
problem solved, because I do not know how it is, the field is not added to the table in the database . But on Friday , when it can indeed query to the field . I just open the database implementation, but can not check into this field. Very tricky question . However , to solve the like. Thank you for the answer ! Points on San Leba !

没有评论:

发表评论