my java code like this:
public class Monitorlog{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
int id;//pk
String sn; // unique constraints(sn,checkpoint)
String checkpoint;
}
public interface MonitorlogDao extends JpaRepository<Monitorlog, Integer>{}
@Service
public class MonitorlogService{
@Autowired
MonitorlogDao monitorlogDao;
public MonitorlogDao getMonitorlog(){
return monitorlogDao;
}
}
The test is like this:
public void testMonitorlogSerivce(){
Monitorlog m = new Monitorlog();
m.setSn("aa");
m.setCheckpoint("bb");
monitorlogService.getMonitorlogDao().save(m);
m = new Monitorlog();
m.setSn("aa");
m.setCheckpoint("bb");
// SQL insert failed here
try{
monitorlogService.getMonitorlogDao().save(m);
}catch(Exception e){
log("",e);
}
}
The secode save(m) is failed , it would like throw a exception, but not. the m.getId() is 0, but no exception catched, why? I use sprint boot ver 2.0.0M. UNIQUE INDEX
CREATE UNIQUE INDEX [IND_IDNO_POSITIONKIND_CHECKPOINT_1] ON
[dbo].[MONITORLOG] ([CHECKPOINT] DESC, [SN] ASC)
WITH (IGNORE_DUP_KEY = ON)