Java Hibernate表未映射
我收到这个错误Java Hibernate表未映射,java,hibernate,jboss,Java,Hibernate,Jboss,我收到这个错误 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.QuerySyntaxExceptio
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;
<?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>
static public ServerSettings GetServerSettings()引发异常
{
List-retList=null;
服务器设置ss=null;
试一试{
会话hsession=HibernateUtil.currentSession();
retList=hsession.createQuery(“作为ss从服务器设置”).list();
if(retList==null | | retList.size()
我们还有一个hibernate.cfg.xml
java:jboss/datasources/MySqlDS
org.hibernate.dialogue.mysqldialogue
和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。有什么建议吗?是映射中的类标记有误。应该是com.mycompany.ServerSettings。
<class name="com.mycompanyServerSettings"
^-- A dot is missing here
<class name="com.mycompanyServerSettings"
^-- A dot is missing here
<mapping resource="com/mycompany/ServerSettings.hbm.xml"/>