此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【BatiTan】截止到2008-07-15 11:56:38的历史汇总数据(不包括此帖):
发帖的总数量:13                       发帖的总分数:660                      每贴平均分数:50                       
回帖的总数量:126                      得分贴总数量:29                       回帖的得分率:23%                      
结贴的总数量:13                       结贴的总分数:660                      
无满意结贴数:4                        无满意结贴分:210                      
未结的帖子数:0                        未结的总分数:0                        
结贴的百分比:100.00%               结分的百分比:100.00%                  
无满意结贴率:30.77 %               无满意结分率:31.82 %                  
敬礼!

解决方案 »

  1.   

    OID设为代理主键,deviceID设成唯一、不空的就可以了吧
    不知道有没有正确理解楼主的意思
      

  2.   

    忘记说了,还有deviceID还要与其他表相关联
    所以在用Session保存,查找的时候
    老是不正确...
    一个额外的问题,就是
    session中session.get(Device.class, deviceID); 
    这句是根据主键的不?
      

  3.   

    你的deviceID肯定是一个外键了,
    所以你用session.get(Device.class, deviceID);根本就是不正确的.
    里面的第二个参数应该是这项记录的id,也就是主键,
    建议另外设置主键.
      

  4.   

    你应该这样,OID是标识列,但不是主键,把DEVICEID作为主建不就行了吗
    然后就可以用GET()方法了
      

  5.   

    session.get(Device.class, deviceID);
    这句是根据主键获得的
    现在我通过把标识OID删除,暂时不用
    然后把deviceID设为主键,并将Hibernate配置文件中改为如下...<hibernate-mapping>
        <class name="hibernate.dao.AgentNode" table="agentNode" schema="dbo" catalog="Xview">
            <id name="deviceId" type="java.lang.Long">
                <column name="deviceID" />
                <generator class="assigned" />
            </id>
            <many-to-one name="groupNode" class="hibernate.dao.GroupNode" fetch="select">
                <column name="parentID" not-null="true" />
            ......将deviceId指定为assigned
    基本效果也实现了,就是少了个OID
    至于那个OID其实也不是必须要..deviceId是为了在所有设备表中生成唯一的标识
    作为一个工具而使用的,因此标识就要手动指定了..
      

  6.   

    这个方法我试了,出现下面的问题
    需要修改什么东西啊...?
    以下是运行后的异常情况:
    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
    log4j:WARN Please initialize the log4j system properly.
    Hibernate: insert into Xview.dbo.deviceTreeID (flag) values (?) select scope_identity()
    产生的ID: 137
    Hibernate: select groupnode0_.deviceID as deviceID0_0_, groupnode0_.name as name0_0_, groupnode0_.localdesc as localdesc0_0_ from Xview.dbo.groupNode groupnode0_ where groupnode0_.deviceID=?
    Exception in thread "main" org.hibernate.PropertyValueException: not-null property references a null or transient value: hibernate.dao.AgentNode.oid这个是自动生成的映射文件
    <hibernate-mapping>
        <class name="hibernate.dao.AgentNode" table="agentNode" schema="dbo" catalog="Xview">
            <id name="deviceId" type="java.lang.Long">
                <column name="deviceID" />
                <generator class="assigned" />
            </id>
            <many-to-one name="groupNode" class="hibernate.dao.GroupNode" fetch="select">
                <column name="parentID" not-null="true" />
            </many-to-one>
            <property name="oid" type="java.lang.Long">
                <column name="oID" not-null="true" />
            </property>
           .....
            <set name="cncrFrames" inverse="true">
                <key>
                    <column name="parentID" not-null="true" />
                </key>
                <one-to-many class="hibernate.dao.CncrFrame" />
            </set>
        </class>
    </hibernate-mapping>
      

  7.   

    你不是已经删除OIDl了么?好像你没有在*.HBM.XML里面删除掉OID,去掉那个节点就可以了deviceID作为主键可以用外键的生成形式,做个onetoone,这样就不用手动添加主键了
      

  8.   

    映射文件我是已经删了
    只是针对5楼的,请教如何去该这个文件
    来实现OID作为标识自动增长...