2011-08-18 225 views
1

我收到此錯誤休眠表沒有映射

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) 

當嘗試部署我的應用程序。

我的類被稱爲ServerSettings.java - 它看起來像

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; 

我們的persistence.xml看起來像

<?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-unit 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> 

我們也有一個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> 

和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> 

通常這個錯誤是把表名而不是在HQL類名時產生 - 但是這不是這裏的情況。這也是以前在JBoss AS5中工作 - 我將它移動到JBoss AS7。有什麼建議?

+0

是您映射中類標記的錯字。應該是com.mycompany.ServerSettings。 – Kathir

回答

3
<class name="com.mycompanyServerSettings" 
          ^-- A dot is missing here 

此外,ServerSettings.hbm.xml未在主hibernate.cfg.xml文件引用。您應該在session-factory元素中包含這樣的元素:

<mapping resource="com/mycompany/ServerSettings.hbm.xml"/>