package com.provinceoa.hospital.dao;import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List;import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.LockMode; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.criterion.Example;import com.provinceoa.hospital.model.DepCostsDetails;import java.util.*;/** * Data access object (DAO) for domain model class DepCostsDetails. * * @see .DepCostsDetails * @author MyEclipse Persistence Tools */public class DepCostsDetailsDAO extends BaseHibernateDAO { private static final Log log = LogFactory.getLog(DepCostsDetailsDAO.class); // property constants public static final String DEP_NAME = "depName"; public static final String NUM_OF_TRAINING_PERSON = "numOfTrainingPerson"; public static final String NUM_OF_AWARDED_PERSON = "numOfAwardedPerson"; public static final String NUM_OF_DEDUCTED_PERSON = "numOfDeductedPerson"; public static final String HOSPITAL_AVERAGE_PAY = "hospitalAveragePay"; public static final String PAY_OF_PERSON = "payOfPerson"; public static final String NUM_OF_PRACTICE_PERSON = "numOfPracticePerson"; public static final String PAY_OF_PRACTICE_PERSON = "payOfPracticePerson"; public static final String TRAINING_PERSON_AVERAGE_PAY = "trainingPersonAveragePay"; public static final String PUBLIC_SERVICE_FEE = "publicServiceFee"; public static final String EQUIPMENT_DEPRECIATION = "equipmentDepreciation"; public static final String EQUIPMENT_STORE_BASISE = "equipmentStoreBasise"; public static final String GENERAL_EQUIPMENT_COSTS = "generalEquipmentCosts"; public static final String MEDICAL_MATERIAL_COSTS = "medicalMaterialCosts"; public static final String DESIFECTION_DRUGS_COSTS = "desifectionDrugsCosts"; public static final String MATERIAL_COST_FOR_OPERATION = "materialCostForOperation"; public static final String INTERVENTION_MATERIAL_COSTS = "interventionMaterialCosts"; public static final String WASHING_COST = "washingCost"; public static final String SUPPLY_DECIFECTION_DRUGS_COSTS = "supplyDecifectionDrugsCosts"; public static final String WATER_POWER_COSTS = "waterPowerCosts"; public static final String GENERAL_MAINTENANCE_COSTS = "generalMaintenanceCosts"; public static final String EQUIPMENT_MAINTENCE_COSTS = "equipmentMaintenceCosts"; public static final String WATER_POWER_MATERIAL_COSTS = "waterPowerMaterialCosts"; public static final String OXYGEN_CHARGES = "oxygenCharges"; public static final String CULTRUE_FEE = "cultrueFee"; public static final String DINNER = "dinner"; public static final String OTHER_COST = "otherCost"; public static final String TOTAL_COSTS = "totalCosts"; public static final String STEADY_COSTS = "steadyCosts"; public static final String CHANGING_COSTS = "changingCosts"; // The method is used for saving a DepCostsDetails instance public boolean save(DepCostsDetails transientInstance) { log.debug("saving DepCostsDetails instance"); Session s = null; try { s = getSession(); Transaction t = s.beginTransaction(); s.save(transientInstance); t.commit(); log.debug("save successful"); return true; } catch (RuntimeException re) { log.error("save failed", re); re.printStackTrace(); return false; } finally { if (s.isOpen()) s.close(); } } }这是部分代码!
把它添加到hibernate.cfg.xml文件中,就ok了
复合主键什么的会影响的,
<?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 package="com.provinceoa.hospital.model">
<class name="DepCostsDetails" table="dep_costs_details" catalog="provinceoa">
<id name="costsDetailsNum" type="integer">
<column name="CostsDetailsNum" />
<generator class="assigned" />
</id>
<many-to-one name="department" class="com.provinceoa.dao.Department" fetch="select">
<column name="DepNum" />
</many-to-one>
<property name="depName" type="string">
<column name="DepName" length="200" />
</property>
<property name="numOfTrainingPerson" type="integer">
<column name="NumOfTrainingPerson" />
</property>
<property name="numOfAwardedPerson" type="integer">
<column name="NumOfAwardedPerson" />
</property>
<property name="numOfDeductedPerson" type="integer">
<column name="NumOfDeductedPerson" />
</property>
<property name="hospitalAveragePay" type="float">
<column name="HospitalAveragePay" precision="12" scale="0" />
</property>
<property name="payOfPerson" type="float">
<column name="PayOfPerson" precision="12" scale="0" />
</property>
<property name="numOfPracticePerson" type="integer">
<column name="NumOfPracticePerson" />
</property>
<property name="payOfPracticePerson" type="float">
<column name="PayOfPracticePerson" precision="12" scale="0" />
</property>
<property name="trainingPersonAveragePay" type="float">
<column name="TrainingPersonAveragePay" precision="12" scale="0" />
</property>
<property name="publicServiceFee" type="float">
<column name="PublicServiceFee" precision="12" scale="0" />
</property>
<property name="equipmentDepreciation" type="float">
<column name="EquipmentDepreciation" precision="12" scale="0" />
</property>
<property name="equipmentStoreBasise" type="float">
<column name="EquipmentStoreBasise" precision="12" scale="0" />
</property>
<property name="generalEquipmentCosts" type="float">
<column name="GeneralEquipmentCosts" precision="12" scale="0" />
</property>
<property name="medicalMaterialCosts" type="float">
<column name="MedicalMaterialCosts" precision="12" scale="0" />
</property>
<property name="desifectionDrugsCosts" type="float">
<column name="DesifectionDrugsCosts" precision="12" scale="0" />
</property>
<property name="materialCostForOperation" type="float">
<column name="MaterialCostForOperation" precision="12" scale="0" />
</property>
<property name="interventionMaterialCosts" type="float">
<column name="InterventionMaterialCosts" precision="12" scale="0" />
</property>
<property name="washingCost" type="float">
<column name="WashingCost" precision="12" scale="0" />
</property>
<property name="supplyDecifectionDrugsCosts" type="float">
<column name="SupplyDecifectionDrugsCosts" precision="12" scale="0" />
</property>
<property name="waterPowerCosts" type="float">
<column name="WaterPowerCosts" precision="12" scale="0" />
</property>
<property name="generalMaintenanceCosts" type="float">
<column name="GeneralMaintenanceCosts" precision="12" scale="0" />
</property>
<property name="equipmentMaintenceCosts" type="float">
<column name="EquipmentMaintenceCosts" precision="12" scale="0" />
</property>
<property name="waterPowerMaterialCosts" type="float">
<column name="WaterPowerMaterialCosts" precision="12" scale="0" />
</property>
<property name="oxygenCharges" type="float">
<column name="OxygenCharges" precision="12" scale="0" />
</property>
<property name="cultrueFee" type="float">
<column name="CultrueFee" precision="12" scale="0" />
</property>
<property name="dinner" type="float">
<column name="Dinner" precision="12" scale="0" />
</property>
<property name="otherCost" type="float">
<column name="OtherCost" precision="12" scale="0" />
</property>
<property name="totalCosts" type="float">
<column name="TotalCosts" precision="12" scale="0" />
</property>
<property name="steadyCosts" type="float">
<column name="SteadyCosts" precision="12" scale="0" />
</property>
<property name="changingCosts" type="float">
<column name="ChangingCosts" precision="12" scale="0" />
</property>
<property name="createDate" type="date">
<column name="CreateDate" length="10" />
</property>
</class>
</hibernate-mapping>这个是:DepCostsDetails.hbm.xml
package com.provinceoa.hospital.dao;import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;import com.provinceoa.hospital.model.DepCostsDetails;import java.util.*;/**
* Data access object (DAO) for domain model class DepCostsDetails.
*
* @see .DepCostsDetails
* @author MyEclipse Persistence Tools
*/public class DepCostsDetailsDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(DepCostsDetailsDAO.class);
// property constants
public static final String DEP_NAME = "depName";
public static final String NUM_OF_TRAINING_PERSON = "numOfTrainingPerson";
public static final String NUM_OF_AWARDED_PERSON = "numOfAwardedPerson";
public static final String NUM_OF_DEDUCTED_PERSON = "numOfDeductedPerson";
public static final String HOSPITAL_AVERAGE_PAY = "hospitalAveragePay";
public static final String PAY_OF_PERSON = "payOfPerson";
public static final String NUM_OF_PRACTICE_PERSON = "numOfPracticePerson";
public static final String PAY_OF_PRACTICE_PERSON = "payOfPracticePerson";
public static final String TRAINING_PERSON_AVERAGE_PAY = "trainingPersonAveragePay";
public static final String PUBLIC_SERVICE_FEE = "publicServiceFee";
public static final String EQUIPMENT_DEPRECIATION = "equipmentDepreciation";
public static final String EQUIPMENT_STORE_BASISE = "equipmentStoreBasise";
public static final String GENERAL_EQUIPMENT_COSTS = "generalEquipmentCosts";
public static final String MEDICAL_MATERIAL_COSTS = "medicalMaterialCosts";
public static final String DESIFECTION_DRUGS_COSTS = "desifectionDrugsCosts";
public static final String MATERIAL_COST_FOR_OPERATION = "materialCostForOperation";
public static final String INTERVENTION_MATERIAL_COSTS = "interventionMaterialCosts";
public static final String WASHING_COST = "washingCost";
public static final String SUPPLY_DECIFECTION_DRUGS_COSTS = "supplyDecifectionDrugsCosts";
public static final String WATER_POWER_COSTS = "waterPowerCosts";
public static final String GENERAL_MAINTENANCE_COSTS = "generalMaintenanceCosts";
public static final String EQUIPMENT_MAINTENCE_COSTS = "equipmentMaintenceCosts";
public static final String WATER_POWER_MATERIAL_COSTS = "waterPowerMaterialCosts";
public static final String OXYGEN_CHARGES = "oxygenCharges";
public static final String CULTRUE_FEE = "cultrueFee";
public static final String DINNER = "dinner";
public static final String OTHER_COST = "otherCost";
public static final String TOTAL_COSTS = "totalCosts";
public static final String STEADY_COSTS = "steadyCosts";
public static final String CHANGING_COSTS = "changingCosts"; // The method is used for saving a DepCostsDetails instance
public boolean save(DepCostsDetails transientInstance) {
log.debug("saving DepCostsDetails instance");
Session s = null;
try {
s = getSession();
Transaction t = s.beginTransaction();
s.save(transientInstance);
t.commit();
log.debug("save successful");
return true;
} catch (RuntimeException re) {
log.error("save failed", re);
re.printStackTrace();
return false;
} finally {
if (s.isOpen())
s.close();
}
} }这是部分代码!
<?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/provinceoa
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">
Loaclhost_MySql
</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.password"></property> <property name="hibernate.jdbc.batch_size">30</property> <property name="hibernate.jdbc.batch_size">100</property> <property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<!-- configuration pool via c3p0-->
<property name="c3p0.acquire_increment">10</property>
<property name="c3p0.idle_test_period">100</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.max_size">3000</property>
<property name="c3p0.time_out">6000</property>
<property name="c3p0.max_statement">50</property>
<property name="jdbc.batch_size">30</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">
org.hibernate.cache.EhCacheProvider
</property>
<property name="cache.use_query_cache">true</property>
<!-- Mapping resources --> <mapping resource="com/provinceoa/dao/User.hbm.xml" />
<mapping resource="com/provinceoa/dao/DocumentFile.hbm.xml" />
<mapping resource="com/provinceoa/dao/Userinfo.hbm.xml" />
<mapping resource="com/provinceoa/dao/Document.hbm.xml" /> <!-- mapping resource="com/provinceoa/dao/DocumentModel.hbm.xml"/--> <mapping resource="com/provinceoa/dao/DocumentEditor.hbm.xml" />
<mapping resource="com/provinceoa/dao/DocumentReader.hbm.xml" /> <mapping resource="com/provinceoa/dao/ReceiveReg.hbm.xml" />
<mapping resource="com/provinceoa/dao/Company.hbm.xml" />
<mapping resource="com/provinceoa/dao/Department.hbm.xml" /> <!-- mapping resource="com/provinceoa/dao/DocumentModel.hbm.xml"/-->
<mapping resource="com/provinceoa/dao/ArchivesTemp.hbm.xml" /> <mapping resource="com/provinceoa/dao/DraftSheet.hbm.xml" />
<mapping resource="com/provinceoa/dao/Authority.hbm.xml" />
<mapping resource="com/provinceoa/dao/SysParameter.hbm.xml" />
<mapping resource="com/provinceoa/dao/AttachmentReg.hbm.xml" />
<mapping
resource="com/provinceoa/dao/SysParameterClass.hbm.xml" />
<mapping resource="com/provinceoa/dao/UnitType.hbm.xml" /> <mapping resource="com/provinceoa/dao/DistributeSheet.hbm.xml" /> <mapping
resource="com/provinceoa/dao/PigeonholeRegister.hbm.xml" /> <mapping resource="com/provinceoa/dao/Boxre.hbm.xml" />
<mapping resource="com/provinceoa/dao/CalendarTemp.hbm.xml" />
<mapping resource="com/provinceoa/dao/DiaryTemp.hbm.xml" />
<mapping resource="com/provinceoa/dao/DiaryReply.hbm.xml" />
<mapping
resource="com/provinceoa/dao/TaskPrivilegeTemp.hbm.xml" />
<mapping resource="com/provinceoa/dao/ForumTemp.hbm.xml" />
<mapping resource="com/provinceoa/dao/ForumReply.hbm.xml" />
<mapping resource="com/provinceoa/dao/ForumManageTemp.hbm.xml" />
<mapping resource="com/provinceoa/dao/PPrivilege.hbm.xml" />
<mapping resource="com/provinceoa/dao/PUserBase.hbm.xml" />
<mapping resource="com/provinceoa/dao/PUserExt.hbm.xml" />
<mapping resource="com/provinceoa/dao/PUserLog.hbm.xml" />
<mapping resource="com/provinceoa/dao/PGroup.hbm.xml" />
<mapping resource="com/provinceoa/dao/PGroupPrv.hbm.xml" />
<mapping resource="com/provinceoa/dao/DistributeUnit.hbm.xml" />
<mapping resource="com/provinceoa/dao/DistributeMode.hbm.xml" /> <!-- mapping resource="com/provinceoa/dao/DistributeState.hbm.xml"/--> <mapping
resource="com/provinceoa/dao/ArchivesTempReader.hbm.xml" />
<mapping resource="com/provinceoa/dao/ArchivesTempUser.hbm.xml" /> <mapping
resource="com/provinceoa/dao/DocDistributeState.hbm.xml" /> <mapping
resource="com/provinceoa/dao/ArchivesTempAttachment.hbm.xml" />
<mapping resource="com/provinceoa/dao/DocHistory.hbm.xml" />
<mapping
resource="com/provinceoa/dao/Distributemode_Unit.hbm.xml" /> <mapping resource="com/provinceoa/dao/BackInfo.hbm.xml" />
<mapping resource="com/provinceoa/dao/Feedback.hbm.xml" />
<mapping resource="com/provinceoa/dao/DataBaseBackInfo.hbm.xml" />
<mapping resource="com/provinceoa/dao/ShortNews.hbm.xml" />
<mapping
resource="com/provinceoa/dao/ShortNewsAttachment.hbm.xml" />
<mapping resource="com/provinceoa/dao/ShortNewsStore.hbm.xml" />
<mapping resource="com/provinceoa/dao/OutRegister.hbm.xml" />
<mapping resource="com/provinceoa/dao/LeaveRegister.hbm.xml" />
<mapping resource="com/provinceoa/dao/EvectionRegister.hbm.xml" />
<mapping resource="com/provinceoa/dao/KaoQin.hbm.xml" />
<mapping resource="com/provinceoa/dao/AddressList.hbm.xml" />
<mapping resource="com/provinceoa/dao/AddressListSort.hbm.xml" />
<mapping resource="com/provinceoa/dao/Chat.hbm.xml" />
<mapping resource="com/provinceoa/dao/NewsAttachment.hbm.xml" />
<mapping
resource="com/provinceoa/hospital/model/DepCostsDetails.hbm.xml" />
<mapping
resource="com/provinceoa/hospital/model/DepDeductCharge.hbm.xml" />
<mapping
resource="com/provinceoa/hospital/model/DepPrizeCharge.hbm.xml" />
<mapping
resource="com/provinceoa/hospital/model/DepPrizeOut.hbm.xml" />
<mapping
resource="com/provinceoa/hospital/model/DepStoreMoney.hbm.xml" />
<mapping
resource="com/provinceoa/hospital/model/DepTotalIncome.hbm.xml" />
<mapping
resource="com/provinceoa/hospital/model/StatusPrizeOut.hbm.xml" />
</session-factory>
</hibernate-configuration>
这个事hibernate.cfg.xml
setCostsDetailsNum(id);
}你在DepCostsDetails.java文件中加多这个方法试试看
我看你的那个配置中只有 costsDetailsNum 这个列名字,没有id这个列你是否设置了hibernate生成Id主键??如果没有的话,应该再好好配置一下拉