我正在使用hibernate連接到Postgres數據庫。在數據庫中有一個表,其中一列被設置爲存儲將該記錄插入該表中的當前時間。當我從Postgres接口插入記錄時,當前時間會自動填充。Postgres數據庫表中的列未自動填充
但是,當我嘗試從Hibernate插入記錄時,記錄不會被數據庫自動插入到當前時間列中。
Query dateQuery=session.createQuery("select b.boilerPlateContent from Boiler_Plates b join b.bt_contracts c where c.contractId=:val order by b.boilerPlateContent desc)").setEntity("val",ct);
Iterator dateIterator = dateQuery.list().iterator();
String latestBoilerPlate=(String)dateIterator.next();
System.out.println(latestBoilerPlate);
Pattern p=Pattern.compile("\\d+");
Matcher m=p.matcher(latestBoilerPlate);
while(m.find()){
lastEntered=m.group();
nextBoilerPlateNumber=Integer.parseInt(m.group());
}
nextBoilerPlateNumber++;
Boiler_Plates bp=new Boiler_Plates();
bp.setBoiler_plate_id(boilerPlateId);
boilerPlateText="bp"+nextBoilerPlateNumber;
bp.setBoilerPlateContent(boilerPlateText);
bp.setBoilerPlateName("Test");
//bp.setInsertTime();
bp.setContract(ct);
session.save(bp);
tx.commit();
您的回答幫助我解決了這個問題。我將屬性中的插入屬性設置爲false,並且運行良好。 –
Alok