当我尝试在表上选择其中一列是外键时出现此错误:
select count(*) from cards where username = 'name';
我是通过java jdbc来做的,所以我觉得我的映射有些错误,因为通过MySql命令行的相同查询工作得很好:
<many-to-one name="users" class="table" update="false" insert="false" fetch="select">
<column name="username" length="45" not-null="true" />
</many-to-one>
2013-03-02 12:19:03,660 INFO [http-bio-8080-exec-5] (NullableType.java:203) - could not read column value from result set: username; Column 'username' not found.
2013-03-02 12:19:03,663 WARN [http-bio-8080-exec-5] (JDBCExceptionReporter.java:100) - SQL Error: 0, SQLState: S0022
2013-03-02 12:19:03,664 ERROR [http-bio-8080-exec-5] (JDBCExceptionReporter.java:101) - Column 'username' not found.
我想这个:
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql.html#d0e13696
第16.1.2和16.1.3节可能是我的问题的答案,但我无法弄清楚......
答案 0 :(得分:2)
错误消息指出:
无法从结果集中读取列值:username;未找到“用户名”列。
select count(*) from ...
的结果集没有名为username
的列。它只包含一列,即计数。
答案 1 :(得分:0)
尝试执行
select count(*) from cards where `cards`.username='name';
答案 2 :(得分:0)
for get fields不应使用“Select *”
应该使用“select count(username)from cards where username ='name';”表达。