我正在将应用程序从Hibernate 4.3.6.Final迁移到5.0.9.Final,然后再迁移到5.2.0.Final。 Currentley我遇到了HQL查询的问题,这些查询不使用完全限定名。 该应用程序在每个对象类的mit hbm.xml映射文件的组合中使用hibernate.cfg.xml配置文件。注释仅用于也使用hibernate-search的类中。 对于数据选择,应用程序使用HQL查询,只有少数查询是标准查询。
以下HQL查询在4.3.6中完美运行:
Organization temp = (Organization) session.createQuery("FROM Organization o WHERE o.pid = "+pid).setMaxResults(1).uniqueResult();
在5.0.9.Final中我得到以下异常:
java.lang.IllegalArgumentException: org.hibernate.QueryException: in expected: o [FROM Organization o WHERE o.pid = 5]
如果我按以下方式更改查询,一切都很好:
Organization temp = (Organization) session.createQuery("FROM at.nettania.dev.ntacadmin.core.organization.Organization o WHERE o.pid = "+pid).setMaxResults(1).uniqueResult();
然而,该应用程序有很多查询,这些查询都以相同的方式编写,并且在文档中它们不使用完全限定的类名。因此我可能遇到配置问题,希望有人能给我一个建议。
Organization.hbm.xml文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="at.nettania.dev.ntacadmin.core.organization.Organization" table="NTACADMIN_ORGANIZATION">
<id name="pid" type="int">
<column name="PID" />
<generator class="native" />
</id>
<property name="creationDate" type="java.util.Date">
<column name="CREATIONDATE" />
</property>
<property name="changeDate" type="java.util.Date">
<column name="CHANGEDATE" />
</property>
<property name="locale" type="java.util.Locale">
<column name="LOCALE" />
</property>
<property name="timeZoneId" type="java.lang.String">
<column name="TIMEZONEID" />
</property>
<property name="deleted" type="boolean">
<column name="DELETED" />
</property>
<property name="enabled" type="boolean">
<column name="ENABLED" />
</property>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="shortcut" type="java.lang.String">
<column name="SHORTCUT" />
</property>
</hibernate-mapping>
当前hibernate.cfg.xml文件的最重要设置如何:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<!--
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
-->
<!--
Database configuration
-->
<property name="connection.url">jdbc:mysql://localhost/testing</property>
<property name="connection.username">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password“>****</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>
<!-- thread is the short name for org.hibernate.context.ThreadLocalSessionContext and let Hibernate bind the session automatically to the thread -->
<property name="current_session_context_class">thread</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">false</property>
<!-- automatic creation of tables -->
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<!-- JDBC Batch Size -->
<property name="hibernate.jdbc.batch_size">20</property>
<!-- Organization mappings -->
<mapping class="at.nettania.dev.ntacadmin.core.organization.Organization" resource="at/nettania/dev/ntacadmin/core/organization/Organization.hbm.xml"/>
</session-factory>
</hibernate-configuration>
谢谢你, 弗洛里安
答案 0 :(得分:2)
我认为您需要从映射标记中删除class属性。资源是指在使用注释时使用xml文件和类。