2012-09-13 36 views
0

我想通过Hibernate 4.1从JSP的MySQL表中访问成员列表。休眠MySQL:代码抛出SQLGrammarException

当我执行代码时,我在页面中收到此异常。

org.apache.jasper.JasperException: Exception in JSP: /home.jsp:27 
org.hibernate.exception.SQLGrammarException: You have an error in your SQL syntax; 
    check the manual that corresponds to your MySQL server version 
    for the right syntax to use near '.members members0_' at line 1 

详细的异常显示以下行的罪魁祸首......

List<Members> result = ses.createQuery("from Members").list(); 

Members.hbm.xml如下...

<hibernate-mapping> 
<class name="com.stichon.ets.db.Members" table="members" catalog="stiadmin_ets"> 
    <id name="idMembers" type="java.lang.Integer"> 
     <column name="id_members" /> 
     <generator class="identity" /> 
    </id> 
    <property name="initials" type="string"> 
     <column name="`initials`" length="15" /> 
    </property> 
    <property name="firstName" type="string"> 
     <column name="`first_name`" length="45" /> 
    </property> 
    <property name="lastName" type="string"> 
     <column name="`last_name`" length="45" /> 
    </property> 
    <property name="mobile" type="string"> 
     <column name="`mobile`" length="15" not-null="true" /> 
    </property> 
    <set name="notificationses" table="notifications" inverse="true" lazy="true" fetch="select"> 
     <key> 
      <column name="id_member" /> 
     </key> 
     <one-to-many class="com.stichon.ets.db.Notifications" /> 
    </set> 
</class> 
</hibernate-mapping> 

添加 “`”(反剔)列名没有帮助.... :(

更新:日志文件中的SQL查询

Hibernate: select devices0_.`idDevices` as idDevices1_0_, devices0_.`name` as name2_0_, devices0_.`desc` as desc3_0_ from stiadmin_ets.stiadmin_ets.`devices` devices0_ 

我在这里看到2个问题

  1. 其附加0_表名,1_0_到第1场,2_0_到第2个等。
  2. 它附加的数据库名称stiadmin_ets.stiadmin_ets。可能与hbm文件中的目录attrib有关。将检查...

在此先感谢

+0

问题已解决。我使用的是MySQLDialect而不是MySQL5Dialect。我愚蠢。 – SSG

回答

0

我的坏!

问题已解决。我使用的是MySQLDialect而不是MySQL5Dialect。同时从主cfg xml中删除default_schema。