我们正在准备部署新的网络应用程序。我们改变了包含罐子的方式,从手动将它们转移到web-inf / lib到使用eclipse的部署组件将它们从一个公共位置动态移动到web-inf / lib中,为我们的lib创建了一个存储库。这个策略适用于除了一个罐子之外的所有东西......我们的休眠实体所在的那个。
罐子在那里,我们可以看到它。它在类路径中,我们可以实例化它。但是当我们运行时,我们会得到未知实体的异常,就好像来自目标实体的注释从未运行过一样。当我们用“annotatedClasses”列表替换“packagesToScan”声明时,它可以正常工作。然而,我们的包裹托斯卡看起来是对的。我更倾向于使用灵活的软件包,而不是开发人员每次都要做出容易忘记的步骤来宣布他们的课程。
任何人都知道为什么会这样?
spring config(下面同时显示所有三个,实际上我们一次评论一个):
<bean id="rptappSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="rptappDataSource" />
<!-- works -->
<property name="annotatedClasses">
<list><value>a.b.c.report.model.table.BOReportTask</value></list>
</property>
<!-- does not work -->
<property name="packagesToScan">
<list><value>a.b.c.report.model.table</value></list>
</property>
<!-- also does not work -->
<property name="packagesToScan" value="a.b.*" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
<prop key="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</prop>
<prop key="hibernate.bytecode.provider">javassist</prop>
<prop key="hibernate.show_sql">${hibernate.show.sql}</prop>
<prop key="format_sql">false</prop>
<prop key="use_sql_comments">false</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.default_schema">K702PRDR</prop>
</props>
</property>
</bean>
例外:
Caused by: org.hibernate.hql.ast.QuerySyntaxException: BOReportTask is not mapped [from BOReportTask r where r.reportStatus = :status order by r.submissionTimestamp asc]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:313)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3353)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3237)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:724)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:575)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:292)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760)
at a.b.c.report.dao.hibernate.table.ReportTaskDao.fetchByStatus(ReportTaskDao.java:68)
答案 0 :(得分:2)
所以我最近重新发现了这篇文章,并认为我会为后代发布解决方案。在RAD中导出jar时,jar向导在向导的第一页上有一个名为“Add Directory Entries”的复选框。检查一下。没有它,我的packagesToScan引用,它是包含其中实体的包的根(因为有多个实体包),将无法找到。它的行为就像没有权利一样。选中此选项会向清单添加内容,并使注释扫描程序找到类。