<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration> <session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/Sales
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">MySql</property>
<property name="connection.password">ok</property>
<property name="connection.driver_class">
org.gjt.mm.mysql.Driver
</property>
<property name="show_sql">true</property>
<mapping resource="com/fund/to/FinancialAccount.hbm.xml" />
<mapping resource="com/fund/to/Sales.hbm.xml" />
<mapping resource="com/fund/to/Fund.hbm.xml"></mapping> </session-factory></hibernate-configuration>

解决方案 »

  1.   

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
        <class name="com.fund.to.Fund" table="fund" catalog="sales">
            <id name="fundNo" type="java.lang.Integer">
                <column name="FUND_NO" />
                <generator class="increment" />
            </id>
            <property name="fundName" type="java.lang.String">
                <column name="FUND_NAME" length="40" />
            </property>
            <property name="price" type="java.lang.Double">
                <column name="PRICE" precision="10" />
            </property>
            <property name="description" type="java.lang.String">
                <column name="DESCRIPTION" length="100" />
            </property>
            <property name="status" type="java.lang.String">
                <column name="STATUS" length="50" />
            </property>
            <property name="createdDate" type="java.util.Date">
                <column name="CREATED_DATE" length="10" />
            </property>
        </class>
    </hibernate-mapping>
      

  2.   

    java.lang.ClassCastException 
    类型转换失败,看你插入数据的时候类型是否正确。
      

  3.   

    Integer类型我没有插入,是主键自增长的
      

  4.   

    把自增长主键改为integer且非自增长的看看,
      

  5.   

    package com.fund.to;import java.util.Date;/**
     * Fund generated by MyEclipse Persistence Tools
     */public class Fund implements java.io.Serializable { // Fields private Integer fundNo; private String fundName; private Double price; private String description; private String status; private Date createdDate; // Constructors /** default constructor */
    public Fund() {
    } /** full constructor */
    public Fund(String fundName, Double price, String description,
    String status, Date createdDate) {
    this.fundName = fundName;
    this.price = price;
    this.description = description;
    this.status = status;
    this.createdDate = createdDate;
    } // Property accessors public Integer getFundNo() {
    return this.fundNo;
    } public void setFundNo(Integer fundNo) {
    this.fundNo = fundNo;
    } public String getFundName() {
    return this.fundName;
    } public void setFundName(String fundName) {
    this.fundName = fundName;
    } public Double getPrice() {
    return this.price;
    } public void setPrice(Double price) {
    this.price = price;
    } public String getDescription() {
    return this.description;
    } public void setDescription(String description) {
    this.description = description;
    } public String getStatus() {
    return this.status;
    } public void setStatus(String status) {
    this.status = status;
    } public Date getCreatedDate() {
    return this.createdDate;
    } public void setCreatedDate(Date createdDate) {
    this.createdDate = createdDate;
    }}
      

  6.   

    <generator class="increment" />改为 <generator class="identity" />
      

  7.   

    已经解决第一个问题,是我的返回值的问题
    第二个已经找到原因,是在生成映射文件的时候
    <property name="price" type="java.lang.Double">
      <column name="PRICE" precision="10" />
    </property>
    这个出了问题,不知道怎么解决
    这个属性在mysql数据库里是decimal(10,2)类型
      

  8.   

    <property name="price" type="java.lang.Double">
      <column name="PRICE" length="10" />
    </property>
      

  9.   

    第二个问题也已经解决是mysql驱动的BUG,我用的是3.2的,换个5.0的就搞定了