I receive this error
11:55:43,125 INFO [org.hibernate.impl.SessionFactoryObjectFactory] (MSC service thread 1-16) Not binding factory to JNDI, no JNDI name configured
11:55:43,215 ERROR [stderr] (MSC service thread 1-16) org.hibernate.hql.ast.QuerySyntaxException: ServerSettings is not mapped [from ServerSettings as ss]
11:55:43,215 ERROR [stderr] (MSC service thread 1-16) at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
11:55:43,215 ERROR [stderr] (MSC service thread 1-16) at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
11:55:43,216 ERROR [stderr] (MSC service thread 1-16) at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
When attempting to deploy my application.
My class is called ServerSettings.java - it looks like
static public ServerSettings GetServerSettings() throws Exception
{
List retList = null;
ServerSettings ss = null;
try {
Session hsession = HibernateUtil.currentSession();
retList = hsession.createQuery("from ServerSettings as ss").list();
if (retList == null || retList.size() <= 0)
return null;
ss = (ServerSettings) retList.get(0);
}
finally
{
HibernateUtil.closeSession();
}
return ss;
our persistence.xml looks like
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-uni开发者_运维知识库t name="primary">
<jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<!-- <sproperty name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
<!-- <property name="hibernate.show_sql" value="false" /> -->
</properties>
We also have a hibernate.cfg.xml
<session-factory>
<property name="datasourceName">java:jboss/datasources/MySqlDS</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
and a ServerSettings.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="com.mycompanyServerSettings" table="server_settings">
<id name="serverSettingsID" type="integer" column="server_settings_id">
<generator class="identity" />
</id>
<version name="updateCounter" column="update_counter"/>
<property name="changedDate" type="timestamp" column="changed_date"/>
<property name="changedBy" type="string" column="changed_by"/>
<property name="createdDate" type="timestamp" column="created_date"/>
<property name="createdBy" type="string" column="created_by"/>
<property name="status" type="string" column="status"/>
<property name="defaultJmsQueueName" type="string" column="default_jms_queue_name" />
<property name="defaultJmsQueueURL" type="string" column="default_jms_queue_url" />
<property name="emailServer" type="string" column="email_server" />
<property name="emailFromAddress" type="string" column="email_from_address" />
<property name="emailUser" type="string" column="email_user" />
<property name="emailPassword" type="string" column="email_password" />
<property name="defaultJMSQueueID" type="string" column="default_jms_queue_id" />
<property name="useEncryption" type="integer" column="use_encryption" />
</class>
Usually this error is caused when using table name instead of class name in hql - but that's not the case here. Also this was working previously in JBoss AS5 - I'm moving it to JBoss AS7. Any advice?
<class name="com.mycompanyServerSettings"
^-- A dot is missing here
Moreover, the ServerSettings.hbm.xml
isn't referenced in the main hibernate.cfg.xml
file. You should have such an element in the session-factory
element:
<mapping resource="com/mycompany/ServerSettings.hbm.xml"/>
精彩评论