我正在使用弹簧形式标签和休眠..
我的jsp页面有以下代码:
<tr><td><form:input path="userEnteredHostNameString" size="30" maxlength="200"/></td>
<td><form:input path="userEnteredDirectoryString" size="30" maxlength="200"/></td>
<td><form:input path="userEnteredUserNameString" size="20" maxlength="20"/></td>
<td><form:input path="userEnteredPasswordString" size="20" maxlength="20"/></td></tr>
我的 location.java 中的 getter 和 setter
public String getUserEnteredHostNameString() {
return userEnteredHostNameString;
}
public void setUserEnteredHostNameString(String userEnteredHostNameString) {
if (userEnteredHostNameString!=null) userEnteredHostNameString = userEnteredHostNameString.toUpperCase();
this.userEnteredHostNameString = userEnteredHostNameString;
}
public String getUserEnteredDirectoryString() {
return userEnteredDirectoryString;
}
public void setUserEnteredDirectoryString(String userEnteredDirectoryString) {
if (userEnteredDirectoryString!=null) userEnteredDirectoryString = userEnteredDirectoryString.toUpperCase();
this.userEnteredDirectoryString = userEnteredDirectoryString;
}
public String getUserEnteredUserNameString() {
return userEnteredUserNameString;
}
public void setUserEnteredUserNameString(String userEnteredUserNameString) {
if (userEnteredUserNameString!=null) userEnteredUserNameString = userEnteredUserNameString.toUpperCase();
this.userEnteredUserNameString = userEnteredUserNameString;
}
public String getUserEnteredPasswordString() {
return userEnteredPasswordString;
}
public void setUserEnteredPasswordString(String userEnteredPasswordString) {
if (userEnteredPasswordString!=null) userEnteredPasswordString = userEnteredPasswordString.toUpperCase();
this.userEnteredPasswordString = userEnteredPasswordString;
}
在我的控制器中,我有以下代码:
FtpScanEvents f = new FtpScanEvents();
if(location.getUserEnteredHostNameString()!=null){
f.setHostName(location.getUserEnteredHostNameString());
}
if(location.getUserEnteredDirectoryString()!=null){
f.setDirectory(location.getUserEnteredDirectoryString());
}
if(location.getUserEnteredUserNameString()!=null){
f.setUserName(location.getUserEnteredUserNameString());
}
if(location.getUserEnteredPasswordString()!=null){
f.setPassword(location.getUserEnteredPasswordString());
}
ftpDao.save(f);
FtpScanEvents 表具有hostName, directory, username, password, locationId, idx, Id
列..
ftpscanevents 的 hbm 映射文件:
<hibernate-mapping package="ca.ups.tundra.model">
<class name="FtpScanEvents" table="FTP_SCAN_EVENTS">
<id name="id" type="long">
<generator class="native"/>
</id>
<property name="hostName" type="string" column="HOSTNAME" length="200"/>
<property name="directory" type="string" column="DIRECTORY" length="200"/>
<property name="userName" type="string" column="USERNAME" length="20"/>
<property name="password" type="string" column="PASSWORD" length="20"/>
<many-to-one name="location" class="Location" cascade="all">
<column name="ID" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
保存(e实体)代码..
@Override
@Transactional(propagation = Propagation.MANDATORY)
public void save(E entity) {
if(entity == null)
throw new NullArgumentException("entity");
Session s = sessionFactory.getCurrentSession();
s.saveOrUpdate(entity);
}
当涉及到ftpDao.save(f);
程序终止并且控制台中没有错误时..任何建议都非常感谢..