List employees = session.createQuery("FROM Employee where date1 between '04-APR-04 02.27.05.187000 AM' and '04-APR-14 02.27.05.187000 AM' and YEAR('04-APR-04 02.27.05.187000 AM')=YEAR('04-APR-04 02.27.05.187000 AM')").list();
我得到這個問題:如何獲得一年日期HQL甲骨文
Hibernate: select emThrployee0_.id as id2_, employee0_.firstName as firstName2_, employee0_.lastName as lastName2_, employee0_.date1 as date4_2_ from emp1 employee0_ where (employee0_.date1 between '04-APR-04 02.27.05.187000 AM' and '04-APR-14 02.27.05.187000 AM') and extract(year from '04-APR-04 02.27.05.187000 AM')=extract(year from '04-APR-04 02.27.05.187000 AM')
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:2214)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at main.StoreData.listEmployees(StoreData.java:68)
at main.StoreData.main(StoreData.java:57)
Caused by: java.sql.SQLException: ORA-30076: invalid extract field for extract source
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1038)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1133)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
... 9 more
我需要一年時間處於休眠甲骨文 但在SQL Server中工作的代碼,但在甲骨文不工作。 我嘗試,但我解決不了請如果知道
感謝
我需要Oracle和SQL服務器的通用HQL代碼。 – sree
我收到Ans:FROM Employee where'date1'在'2014-04-04 08:58:45.000'和'2014-04-14 08:58:45.000'並且摘錄(從date1開始)= to_char(to_timestamp('2014- 04-10 08:58:45.000','yyyy-mm-rr hh:mi:ss.ff am'),'yyyy') – sree