import java.util.Date;
public class Pojo {
private int stopID;
private String stopCD;
private String stopName;
private String stopAlias1;
private String stopAlias2;
private String stopAlias3;
private String stopName_Reg_Lang1;
private String stopName_Reg_Lang2;
private String lastUpdatedBy;
private String delFlag;
private String createRoleID;
private String updateRoleID;
private String createUserID;
private String stopNameRoad;
private String audioFile;
private int stopTypeID;
private double latitude;
private double longitude;
private int radius;
private int latRounded1;
private int longRounded1;
private int latRounded2;
private int longRounded2;
private int latRounded3;
private int longRounded3;
private int jurisdiction;
private int districtID;
private int stateID;
private String mobile;
private int cityType;
private int fontType;
private int cityNameID;
private Date createTime;
private Date lastUpdatedTime;
//setters and getters
}
DAO CLASS METHOD
public JSONObject getSaveToDatabase(List dataHolder) throws ParseException {
List list= new ArrayList();
Session sessionOracle=null;
Pojo Db=new Pojo();
sessionOracle=BaseDAO.getHibernateSession().openSession();
org.hibernate.Transaction txOracle=null;
//list contains record
Db.setStopID((int)list.get(0));
System.out.println(Db.getStopID());
try{
txOracle=sessionOracle.beginTransaction();
System.out.println(sessionOracle.isOpen());
sessionOracle.save(Db);
txOracle.commit();
System.out.println("Data is inserted");
}catch(Exception i){
txOracle.rollback();
i.printStackTrace();
System.out.println("Exception in POI ------"+i.toString());
}
例外:
Hibernate: insert into POI_M_STOP (stop_id, stop_name, stop_alias_name1, stop_alias_name2, stop_alias_name3, stop_cd, stop_type_id, jurisdiction, mobile_number, del_flag, create_user_id, latitude, longitude, create_time, last_updated_time, district_id, state_id, lat_rounded, lat_rounded_2, lat_rounded_3, long_rounded, long_rounded_2, long_rounded_3, audio_file, stop_name_road, city_type, city_name_id, STOP_NAME_REG_LANG1, STOP_NAME_REG_LANG2, LAST_UPDATED_BY, CREATE_ROLE_ID, UPDATED_ROLE_ID, RADIUS_FOR_DETECTION, FONT_TYPE) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
当我在没有hibernate的情况下使用上述查询并在JDBC中使用插入查询时,正在正确插入数据。 我只是检查id列和“session.save(obj)”和“transaction.commit(); - line(1)”。 在第(1)行,它抛出了上述异常。 由于“stop_id”在应用程序中的类型为int,而db中相应的“id”的类型为int。
XXXX.hbm.xml
<hibernate-mapping>
<class name="excel.apsrtc.pojo.Pojo" table="POI_M_STOP">
<id name="stopID" type="int">
<column name="stopID"></column>
</id>
<property name="stopName" type="java.lang.String" column="stop_name"></property>
<property name="stopAlias1" type="java.lang.String" column="stop_alias_name1"></property>
<property name="stopAlias2" type="java.lang.String" column="stop_alias_name2"></property>
<property name="stopAlias3" type="java.lang.String" column="stop_alias_name3"></property>
<property name="stopCD" type="java.lang.String" column="stop_cd"></property>
<property name="stopTypeID" type="int" column="stop_type_id"></property>
<property name="jurisdiction" type="java.lang.String" column="jurisdiction"></property>
<property name="mobile" type="java.lang.String" column="mobile_number"></property>
<property name="delFlag" type="java.lang.String" column="del_flag"></property>
<property name="createUserID" type="java.lang.String" column="create_user_id"></property>
<property name="latitude" type="double" column="latitude"></property>
<property name="longitude" type="double" column="longitude"></property>
<property name="createTime" type="java.util.Date"><column name="create_time" /></property>
<property name="lastUpdatedTime" type="java.util.Date"><column name="last_updated_time" /></property>
<property name="districtID" type="int" column="district_id"></property>
<property name="stateID" type="int" column="state_id"></property>
<property name="latRounded1" type="int" column="lat_rounded"></property>
<property name="latRounded2" type="int" column="lat_rounded_2"></property>
<property name="latRounded3" type="int" column="lat_rounded_3"></property>
<property name="longRounded1" type="int" column="long_rounded"></property>
<property name="longRounded2" type="int" column="long_rounded_2"></property>
<property name="longRounded3" type="int" column="long_rounded_3"></property>
<property name="audioFile" type="java.lang.String" column="audio_file"></property>
<property name="stopNameRoad" type="java.lang.String" column="stop_name_road"></property>
<property name="cityType" type="int" column="city_type"></property>
<property name="cityNameID" type="java.lang.String" column="city_name_id"></property>
<property name="stopName_Reg_Lang1" type="java.lang.String" column="STOP_NAME_REG_LANG1"></property>
<property name="stopName_Reg_Lang2" type="java.lang.String" column="STOP_NAME_REG_LANG2"></property>
<property name="lastUpdatedBy" type="java.lang.String" column="LAST_UPDATED_BY"></property>
<property name="createRoleID" type="java.lang.String" column="CREATE_ROLE_ID"></property>
<property name="updateRoleID" type="java.lang.String" column="UPDATED_ROLE_ID"></property>
<property name="radius" type="java.lang.String" column="RADIUS_FOR_DETECTION"></property>
<property name="fontType" type="java.lang.String" column="FONT_TYPE"></property>
</class>
</hibernate-mapping>
请帮帮我。 提前谢谢。
答案 0 :(得分:0)
您的实体类与映射文件之间存在一些不匹配,例如: fontType
/ FONT_TYPE
。 fontType
字段的类型为int
,而在hbm文件中,它会映射到java.lang.String
。
请查找任何其他类似的不匹配并修复它们。在那之后,你不应再得到那个错误了。