我正在尝试通过Hibernate 4.1从JSP表中访问MySQL表中的成员列表。
每当我执行代码时,我的页面都会出现此异常。
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个问题
提前致谢
答案 0 :(得分:0)
我的坏!
问题已解决。我使用MySQLDialect而不是MySQL5Dialect。还从主cfg xml中删除了default_schema。