我正在使用触发器在Oracle数据库中自动使表的id列自动递增。
这是我的Spring控制器中的代码,
@RequestMapping("/ssuForm/create")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public UmkeiBusinessInfo createSsuForm(@RequestBody UmkeiBusinessInfo umkeiSsu) {
UmkeiBusinessInfo createSsuForm = umkeiBusinessInfoService.create(umkeiSsu);
System.out.println(createSsuForm);
return createSsuForm;
}
如何使用System.out.println查看返回的内容,我看不到列出的id。其他一切都做了。
这里是日志,
|Nexus|Wed Apr 13 00:00:00 SGT 2016|Nexus Street|NexusCity|04|null|80000|0108808550|nexus@nexi.com|1|A|2|P1|B10A218|Sun Apr 03 10:40:28 SGT 2016|null||B10A218|1|0145283459|teniousd@yahoo.com|9|A08|00751A|null|null|null|null|null
请注意,它以Nexus开头,而不是ID。
编辑:
这是/ business / service / impl
中的代码 @Override
public UmkeiBusinessInfo save(UmkeiBusinessInfo umkeiBusinessInfo) {
return update(umkeiBusinessInfo) ;
}
@Override
public UmkeiBusinessInfo create(UmkeiBusinessInfo umkeiBusinessInfo) {
UmkeiBusinessInfoEntity umkeiBusinessInfoEntity = umkeiBusinessInfoJpaRepository.findOne(umkeiBusinessInfo.getUbiId());
if( umkeiBusinessInfoEntity != null ) {
throw new IllegalStateException("already.exists");
}
umkeiBusinessInfoEntity = new UmkeiBusinessInfoEntity();
umkeiBusinessInfoServiceMapper.mapUmkeiBusinessInfoToUmkeiBusinessInfoEntity(umkeiBusinessInfo, umkeiBusinessInfoEntity);
UmkeiBusinessInfoEntity umkeiBusinessInfoEntitySaved = umkeiBusinessInfoJpaRepository.save(umkeiBusinessInfoEntity);
return umkeiBusinessInfoServiceMapper.mapUmkeiBusinessInfoEntityToUmkeiBusinessInfo(umkeiBusinessInfoEntitySaved);
}
@Override
public UmkeiBusinessInfo update(UmkeiBusinessInfo umkeiBusinessInfo) {
UmkeiBusinessInfoEntity umkeiBusinessInfoEntity = umkeiBusinessInfoJpaRepository.findOne(umkeiBusinessInfo.getUbiId());
umkeiBusinessInfoServiceMapper.mapUmkeiBusinessInfoToUmkeiBusinessInfoEntity(umkeiBusinessInfo, umkeiBusinessInfoEntity);
UmkeiBusinessInfoEntity umkeiBusinessInfoEntitySaved = umkeiBusinessInfoJpaRepository.save(umkeiBusinessInfoEntity);
return umkeiBusinessInfoServiceMapper.mapUmkeiBusinessInfoEntityToUmkeiBusinessInfo(umkeiBusinessInfoEntitySaved);
}
,这是实体部分,
//----------------------------------------------------------------------
// ENTITY PRIMARY KEY ( BASED ON A SINGLE FIELD )
//----------------------------------------------------------------------
@NotNull
@Size( min = 1, max = 20 )
private String ubiId;
//----------------------------------------------------------------------
// ENTITY DATA FIELDS
//----------------------------------------------------------------------
@Size( max = 100 )
private String ubiName;
private Date ubiStartDate;
@Size( max = 100 )
private String ubiAddress;
@Size( max = 64 )
private String ubiCity;
@Size( max = 10 )
private String ubiState;
@Size( max = 10 )
private String ubiCountry;
这里是JPA实体部分,
//----------------------------------------------------------------------
// ENTITY PRIMARY KEY ( BASED ON A SINGLE FIELD )
//----------------------------------------------------------------------
@Id
@Column(name="UBI_ID", nullable=false, length=20)
private String ubiId ;
//----------------------------------------------------------------------
// ENTITY DATA FIELDS
//----------------------------------------------------------------------
@Column(name="UBI_NAME", length=100)
private String ubiName ;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="UBI_START_DATE")
private Date ubiStartDate ;
@Column(name="UBI_ADDRESS", length=100)
private String ubiAddress ;
答案 0 :(得分:0)
我刚刚开始工作。
首先,我需要在ORACLE中将数据类型更改为“Number”,然后将所有代码从String更改为BigDecimal。
然后添加Bunti提到的注释,
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="UMKEI_BUSINESS_INFO_SEQ1")
@SequenceGenerator(name="UMKEI_BUSINESS_INFO_SEQ1 ", sequenceName="UMKEI_BUSINESS_INFO_SEQ1", allocationSize=1)
我将增量值传递给客户端。
之前由于dataType而无法正常工作。