2016-04-03 77 views
0

我使用触发器在Oracle数据库中自行增加表的id列。通过Spring MVC从Oracle数据库获取自动递增的ID(主键)

这里是我的春节,控制器代码,

@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|[email protected]|1|A|2|P1|B10A218|Sun Apr 03 10:40:28 SGT 2016|null||B10A218|1|0145283459|[email protected]|9|A08|00751A|null|null|null|null|null 

注意到它与Nexus,而不是ID开始。

下面是什么我的表看起来像片断, enter image description here

编辑:

这里面的代码/业务/服务/ 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 ; 
+1

为什么在世界上你会使用触发器来增加id并且不使用本地音序器? – pczeus

+0

糟糕,我启用了触发器,并自动激活序列。启用触发器后,我什么也没做。 – Luqman

+1

如果您使用的是JPA – Bunti

回答

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而无法工作。

相关问题