应该不是数据库连接的问题,我感觉是你的配置文件有问题,'public_DocClass_info' 是什么?把这部分的配置和程序贴出来!

解决方案 »

  1.   

    是数据库中的表名啊
    PublicDocClassInfo是类名,映射public_DocClass_info数据表名
      

  2.   

    把你的xml贴出来,
    应该是这里面的问题
      

  3.   

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" ><hibernate-mapping>
    <!--
        Created by the Middlegen Hibernate plugin 2.1    http://boss.bekk.no/boss/middlegen/
        http://www.hibernate.org/
    --><class
        name="oa.bean.PublicDocClassInfo"
        table="public_DocClass_info"
    >
        <meta attribute="class-description" inherit="false">
           @hibernate.class
            table="public_DocClass_info"
        </meta>    <id
            name="id"
            type="int"
            column="id"
        >
            <meta attribute="field-description">
               @hibernate.id
                generator-class="assigned"
                type="int"
                column="id"
            </meta>
            <generator class="native" />
        </id>    <property
            name="fatherId"
            type="java.lang.Integer"
            column="fatherId"
            length="10"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="fatherId"
                length="10"
            </meta>
        </property>
        <property
            name="myName"
            type="java.lang.String"
            column="myName"
            length="50"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="myName"
                length="50"
            </meta>
        </property>
        <property
            name="styleCode"
            type="int"
            column="style_code"
            not-null="true"
            length="10"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="style_code"
                length="10"
                not-null="true"
            </meta>
        </property>    <!-- Associations -->
    </class>
    </hibernate-mapping>
      

  4.   

    另外,还有个问题,我估计与此有关的.
    我估计此问题是否与Hibernate中dataSource一项相关,因为在用工具生成hbm文件时,我记得资料上说dataSource一项一定要如下配置(连接MSSqlServer时)
    ==================================
    ……
       <property name="database.userid"                value="sa"/>
       <property name="database.password"              value="123"/>
       <property name="database.schema"                value="dbo"/>
       <property name="database.catalog"               value="oa"/>
    =================================
    于是我在Hibernate的实始化文件中dataSource一段加了如下两个属性
    =================================   
        <property name="schema">
          <value>dbo</value>
        </property>
        <property name="catalog">
          <value>oa</value>
        </property>
    =================================
    结果,初始化时,出错提示说是这两个属性(dataSource)都是只读的,不让改。
      

  5.   

    <generator class="native" />你的数据库表,对这个字段有没有设置,自增!