日期:2014-05-17 浏览次数:20739 次
public class MemberSource implements java.io.Serializable {
private String membSourceNo;
private String membSourceName;
private String membSourceDesc;
@Id
// @GeneratedValue
@Column(name = "MembSourceNo", unique = true, nullable = false)
public String getMembSourceNo() {
return this.membSourceNo;
}
public void setMembSourceNo(String membSourceNo) {
this.membSourceNo = membSourceNo;
}
MemberSource s1 = new MemberSource();
s1.setMembSourceNo("01");
s1.setMembSourceName("现场");
MemberSource s2 = new MemberSource();
s1.setMembSourceNo("02");
s1.setMembSourceName("网上");
try{
memService.addMemberSource(s1);
memService.addMemberSource(s2);
}catch(Exception e){
e.printStackTrace();
}
public boolean addMemberSource(MemberSource s){
log.debug("saving instance");
try{
this.getHibernateTemplate().save(s);
log.debug("save successfully");
}catch(RuntimeException e){
log.debug("save failed "+e);
throw e;
}
return true;
}
Hibernate: insert into LogisticPark.dbo.MemberSource (MembSourceDesc, MembSourceName) values (?, ?)
org.springframework.dao.DataIntegrityViolationException: could not insert: [com.rokinmementity.MemberSource]; SQL [insert into LogisticPark.dbo.MemberSource (MembSourceDesc, MembSourceName) values (?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.rokinmementity.MemberSource]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:637)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
at com.rokinmemdao.RokinMemberDao.addMemberSource(RokinMemberDao.java:91)
Hibernate: insert into LogisticPark.dbo.MemberSource (MembSourceDesc, MembSourceName, MembSourceNo) values (?, ?, ?)
org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be manually a