| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1294 人关注过本帖
标题:c++:cppHibernate问题
只看楼主 加入收藏
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
结帖率:40%
收藏
已结贴  问题点数:20 回复次数:7 
c++:cppHibernate问题
在java里。我生成映射文件、普通的java类,通过hql可以查出数据。

我把映射文件和java类给c++程序,通过cppHibernate调用,报找不到字段错误。

请看映射文件
<hibernate-mapping>
    <class name="com.atman.hci.domain.HciStandardStatements" table="HCI_standard_statements">
        <id name="stdStatementId" type="java.lang.Long">
            <column name="std_statement_id" />
            <generator class="native" />
        </id>
        <property name="ioFormatId" type="java.lang.Long">
            <column name="io_format_id" not-null="true" />
        </property>
        
        <property name="stdStatement" column="std_statement" type="string" not-null="true"/>
        
        <property name="createTime" type="java.sql.Timestamp">
            <column name="create_time" length="19" not-null="true" />
        </property>
        <property name="updateTime" type="java.sql.Timestamp">
            <column name="update_time" length="19" not-null="true" />
        </property>
        <property name="available" type="java.lang.Short">
            <column name="available" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

c++通过cppHibernate访问数据库代码
CppHibernateQuery query = session->createQuery("from HciStandardStatements hc where hc.stdStatementId = 1");
CppHibernateJCollectionObject *wh = query.list();
CppHibernateJObject *el2 = wh->get(0);
CppHibernateJStringObject *res2Str = dynamic_cast<CppHibernateJStringObject *>(el2->getVal("stdStatement"));
printf("%s\n", res2Str->getVal());

报错:
Exception in thread "main" java.lang.NoSuchFieldError: stdStatement
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000000040f4ff, pid=10083, tid=139953762797344
#
# JRE version: 7.0_21-b11
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.21-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [a.out+0xf4ff]  _ZNSs6appendEPKcm@@GLIBCXX_3.4+0xf4ff
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/whh/database/cpphibernate/hs_err_pid10083.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
搜索更多相关主题的帖子: property java 
2013-06-18 17:10
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
我的java类是有有这个属性的。
数据库表结构
CREATE TABLE `HCI_standard_statements` (
    `std_statement_id` BIGINT(8) NOT NULL AUTO_INCREMENT,
    `io_format_id` BIGINT(8) NOT NULL,
    `std_statement` VARCHAR(20) NOT NULL,
    `create_time` DATETIME NOT NULL,
    `update_time` DATETIME NOT NULL,
    `available` TINYINT(4) NOT NULL DEFAULT '1',
    PRIMARY KEY (`std_statement_id`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM
AUTO_INCREMENT=18;

java-pojo类(以下为属性、[默认的构造函数、setter、getter均略])
    private Long stdStatementId;
    private Long ioFormatId;
    private String stdStatement;
    private Timestamp createTime;
    private Timestamp updateTime;
    private Short available;

大家一起努力,共同打造未来!!
2013-06-18 17:16
joy2
Rank: 2
等 级:论坛游民
帖 子:5
专家分:47
注 册:2013-6-18
收藏
得分:10 
很深奥!!!!!
--------------
斗破乾坤 http://www.
2013-06-18 17:40
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
在给大家补点日志:
1:43:23,575 DEBUG QueryTranslatorImpl:243 - HQL: from com.atman.hci.domain.HciStandardStatements
01:43:23,575 DEBUG QueryTranslatorImpl:244 - SQL: select hcistandar0_.std_statement_id as std1_0_, hcistandar0_.io_format_id as io2_0_, hcistandar0_.std_statement as std3_0_, hcistandar0_.create_time as create4_0_, hcistandar0_.update_time as update5_0_, hcistandar0_.available as available0_ from HCI_standard_statements hcistandar0_
01:43:23,576 DEBUG ErrorCounter:91 - throwQueryException() : no errors
01:43:23,581 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
01:43:23,583 DEBUG SQL:111 - select hcistandar0_.std_statement_id as std1_0_, hcistandar0_.io_format_id as io2_0_, hcistandar0_.std_statement as std3_0_, hcistandar0_.create_time as create4_0_, hcistandar0_.update_time as update5_0_, hcistandar0_.available as available0_ from HCI_standard_statements hcistandar0_
Hibernate: select hcistandar0_.std_statement_id as std1_0_, hcistandar0_.io_format_id as io2_0_, hcistandar0_.std_statement as std3_0_, hcistandar0_.create_time as create4_0_, hcistandar0_.update_time as update5_0_, hcistandar0_.available as available0_ from HCI_standard_statements hcistandar0_
01:43:23,591 DEBUG AbstractBatcher:426 - about to open ResultSet (open ResultSets: 0, globally: 0)
01:43:23,592 TRACE BasicExtractor:71 - found [16] as column [std1_0_]
01:43:23,593 DEBUG Loader:1322 - result row: EntityKey[com.atman.hci.domain.HciStandardStatements#16]
01:43:23,596 TRACE BasicExtractor:71 - found [100] as column [io2_0_]
01:43:23,596 TRACE BasicExtractor:71 - found [1000] as column [std3_0_]
01:43:23,600 TRACE BasicExtractor:71 - found [2013-06-04 16:08:17.0] as column [create4_0_]
01:43:23,600 TRACE BasicExtractor:71 - found [2013-06-05 16:08:19.0] as column [update5_0_]
01:43:23,600 TRACE BasicExtractor:71 - found [1] as column [available0_]
01:43:23,601 TRACE BasicExtractor:71 - found [17] as column [std1_0_]
01:43:23,601 DEBUG Loader:1322 - result row: EntityKey[com.atman.hci.domain.HciStandardStatements#17]
01:43:23,601 TRACE BasicExtractor:71 - found [1111] as column [io2_0_]
01:43:23,601 TRACE BasicExtractor:71 - found [11] as column [std3_0_]
01:43:23,601 TRACE BasicExtractor:71 - found [2013-06-03 16:47:14.0] as column [create4_0_]
01:43:23,601 TRACE BasicExtractor:71 - found [2013-06-11 16:47:16.0] as column [update5_0_]
01:43:23,601 TRACE BasicExtractor:71 - found [1] as column [available0_]
01:43:23,601 DEBUG AbstractBatcher:433 - about to close ResultSet (open ResultSets: 1, globally: 1)
01:43:23,602 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
01:43:23,602 DEBUG TwoPhaseLoad:130 - resolving associations for [com.atman.hci.domain.HciStandardStatements#16]
01:43:23,604 DEBUG TwoPhaseLoad:255 - done materializing entity [com.atman.hci.domain.HciStandardStatements#16]
01:43:23,604 DEBUG TwoPhaseLoad:130 - resolving associations for [com.atman.hci.domain.HciStandardStatements#17]
01:43:23,604 DEBUG TwoPhaseLoad:255 - done materializing entity [com.atman.hci.domain.HciStandardStatements#17]
01:43:23,604 DEBUG StatefulPersistenceContext:893 - initializing non-lazy collections
Exception in thread "main" java.lang.NoSuchFieldError: stdStatement

大家一起努力,共同打造未来!!
2013-06-18 17:54
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
现在很怪异,如果是取整型的字段,是可以取出来,取字符串的字段就出这个问题

大家一起努力,共同打造未来!!
2013-06-18 17:54
我有我梦
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:321
专家分:1128
注 册:2013-5-25
收藏
得分:10 
2013-06-18 20:42
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
问题原因找到了。就是表结构的主键,名称必须为id,将主键id从原来的XXX_id调整为id,就好了!

但是这样虽然可以解决,但是感觉很别扭,因为我主键的id如果只能设置为id的话,那可读性就很不好了。

期待有更好的解决方式。

大家一起努力,共同打造未来!!
2013-06-19 13:19
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
综上
cppHibernate当主键为XXX_id时,不能取字符串类型的数据。(整形数据时可以读取的)
将主键从“XXX_id”调整为"id"就可以读取字符串类型的数据了。

大家一起努力,共同打造未来!!
2013-06-20 10:15
快速回复:c++:cppHibernate问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019284 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved