使用Hibernate saveOrUpdate:
的奇怪行为我可以在两种情况下看到日志中修改字段的值。
实体:
@Entity
@Table(name = "SIT_EVENEMENT_QF")
public class EvenementQf {
@Id
@Column(name = "EQF_ID", unique = true, nullable = false)
private Long eqfId;
@Temporal(TemporalType.DATE)
@Column(name = "EQF_DT", nullable = false, length = 7)
private Date eqfDt;
@Column(name = "EQF_COMMENT", length = 4000)
private String eqfComment;
...
}
dao:
public void saveOrUpdate(EvenementQf entity) throws EqfDAOException {
try {
if (entity.getId() != null) {
this.getSession().evict(this.get(entity.getId()));
}
this.getSession().saveOrUpdate(entity);
} catch (HibernateException var4) {
this.log.info("Erreur Hibernate " + var4);
throw var4;
} catch (Exception var5) {
this.log.error("Erreur inattendue : " + var5);
throw var5;
}
}
Hibernate登录调试模式:
没有字段EqfComment,因此使用更新语句:
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:114) - Listing entities:
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.SioTypeLid{tliLib=Ligne simple, tliCod=L, sioLids=<uninitialized>}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.EvenementQf{eqfComment=, eqfIndMarqNat=N, lid=com.rte.siquael.dao.entity.Lid#1476, eqfTypeMateriel=null, eqfEssNo=null, evtGrdAmpleur=null, eqfReprise=null, eqfIndRht=N, blocCoupure=null, eqfConstructeur=null, poste=null, sitPerturbations=[], eqfCod=17003430, eqfIndMarqLoc=O, indicateurZone=N, eqfCommentaireRh=null, eqfCommentaireRj=null, eqfDt=Sun Sep 10 10:10:10 CEST 2017, gesrId=null, eqfId=352082, eqfIrtsyst=N, sitCourtCircuits=[com.rte.siquael.dao.entity.CourtCircuit#337101], tessId=null, statut=E, sitAnomalies=[], eqfCommentaireRht=null, sitEvenementCbs=[], eqfIndTraitement=N, eqfEsrNo=null, motcleId=null, contrainteId=402, eqfRje=null, eqfMarquageDt=Mon Sep 11 16:08:09 CEST 2017, sitStatutAt=com.rte.siquael.dao.entity.SitStatutAt#E, eqfDtMs=0, eqfDtCreat=2017-09-11, eqfIndRj=N, clientId=null, eqfIndRh=N, eqfNoEga=null, sitEcartExploits=[], eqfAvtIncid=null, complementRegionaux=null, eqfDtMscal=212371812122000, eqfBloque=N, eqfOuvNtnLib=null, gessId=null, eqfDtMaj=Tue Sep 12 09:54:46 CEST 2017, eqfIndMarqReg=N, sitActionSuiviRexes=<uninitialized>, eqfOuvLib=null, eqfDateMiseEnService=null, tesrId=null, responsableId=463}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Poste{posIndiceCur=null, clients=<uninitialized>, blocCoupures=<uninitialized>, posAdr=Partenay les bonobonos, sioTypeSite=com.rte.siquael.dao.entity.TypeSite#P, posCoordonneeX=926619.18, posCoordonneeY=6514695.25, posEtat=Existant, posDtIn=1970-01-01, posId=1214, posNumNat=004, cdfIdTypProp=297, posDpde=1970-01-01, posDrfe=null, sioNiveauTensions=<uninitialized>, posDrde=1970-01-01, structureChargeeExploitation=com.rte.siquael.dao.entity.Structure#103, structureAdm=com.rte.siquael.dao.entity.StructureAdm#1312, commentaire=injection-soutirage , sioOuvrage=<uninitialized>, sioPays=com.rte.siquael.dao.entity.Pays#F, sioPsts=<uninitialized>, posCodNat=A.BAI, posDateModifInforef=2017-02-15, posDpfe=null, tranchesBt=<uninitialized>, complementRegionaux=null, posLibCrt=Partenay les bonobonos, posDtHs=null, posDtCre=1997-11-07, posDtMaj=2017-03-16, structureChargeeConduite=com.rte.siquael.dao.entity.Structure#8, posCur=13800B670A522054E043A3681E7C2054}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Poste{posIndiceCur=null, clients=<uninitialized>, blocCoupures=<uninitialized>, posAdr=Partenay les bonobonos, sioTypeSite=com.rte.siquael.dao.entity.TypeSite#P, posCoordonneeX=null, posCoordonneeY=null, posEtat=Existant, posDtIn=1974-01-01, posId=1215, posNumNat=145, cdfIdTypProp=304, posDpde=1989-01-01, posDrfe=null, sioNiveauTensions=<uninitialized>, posDrde=1989-01-01, structureChargeeExploitation=com.rte.siquael.dao.entity.Structure#103, structureAdm=com.rte.siquael.dao.entity.StructureAdm#1312, commentaire=null, sioOuvrage=<uninitialized>, sioPays=com.rte.siquael.dao.entity.Pays#F, sioPsts=<uninitialized>, posCodNat=A.BA5, posDateModifInforef=2014-12-12, posDpfe=null, tranchesBt=<uninitialized>, complementRegionaux=null, posLibCrt=Partenay les bonobonos, posDtHs=null, posDtCre=1997-11-07, posDtMaj=1998-05-29, structureChargeeConduite=com.rte.siquael.dao.entity.Structure#8, posCur=13800B670A512054E043A3681E7C2054}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Lid{sitAnomalies=<uninitialized>, sitEvenementQfs=<uninitialized>, lidNumNat=55S003300, sioTypeLid=com.rte.siquael.dao.entity.SioTypeLid#L, sitEvenementCbs=<uninitialized>, sitEvenementExploits=<uninitialized>, lidDtHs=null, lidDtIn=1974-01-01, sioTrancheTcds=<uninitialized>, structureChefFile=com.rte.siquael.dao.entity.Structure#103, lidDtMaj=2001-07-31, lidDtCre=1997-11-07, lidTer=N, commentaire=null, lidId=1476, silAcaOuvrages=<uninitialized>, sioOuvrages=<uninitialized>, sioNiveauTension=com.rte.siquael.dao.entity.SioNiveauTension#3, silActionCorrs=<uninitialized>, posteA=com.rte.siquael.dao.entity.Poste#1214, sioLits=<uninitialized>, posteB=com.rte.siquael.dao.entity.Poste#1215, sitCourtCircuits=<uninitialized>, lidCodNat=A.BAIL31A.BA5, structureChargeeConduite=com.rte.siquael.dao.entity.Structure#8, lidLib=63kV Partenay les bonobonos}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Structure{sioPostesForStrIdCep=<uninitialized>, strLib=GdP de Longefan, strCmp=0, sioPostesForStrIdCcp=<uninitialized>, clients=<uninitialized>, sitAnomalies=<uninitialized>, strDtCre=1992-02-01, silPersonnesForStrId=<uninitialized>, siqCodifications=<uninitialized>, ssDtFin=null, strIndiceCur=-, sitEvenementExploits=<uninitialized>, strDir=5, strOss=25, sioLidsForStrIdCfd=<uninitialized>, sitSauveEtatSaisies=<uninitialized>, ssDtDeb=null, strSun=S, silActionAmeliorations=<uninitialized>, sioUtilisateurs=<uninitialized>, strCur=D86AC36BE9AF4798937552AE34228317, strDtSup=null, strLoc=St Jean de Maurienne, sioFiltreStds=<uninitialized>, strNumOrdre=5, strCodPos=73300, silAcaOuvrages=<uninitialized>, silGroupeClients=<uninitialized>, sioStructures=<uninitialized>, strId=103, sioProfils=<uninitialized>, sioProfils_1=<uninitialized>, sioLidsForStrIdCcd=<uninitialized>, sitEqfCresRexes=<uninitialized>, sioLits=<uninitialized>, structure=com.rte.siquael.dao.entity.Structure#41, strAdr2=Cedex 1708, typeStructure=com.rte.siquael.dao.entity.TypeStructure#GdP, strAdr1=X, strFax=04XXXXXXXX, strVis=O, silPersonnesForStrIdApp=<uninitialized>, strTel=04XXXXXXXX}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Structure{sioPostesForStrIdCep=<uninitialized>, strLib=Lyon, strCmp=null, sioPostesForStrIdCcp=<uninitialized>, clients=<uninitialized>, sitAnomalies=<uninitialized>, strDtCre=1992-02-01, silPersonnesForStrId=<uninitialized>, siqCodifications=<uninitialized>, ssDtFin=null, strIndiceCur=-, sitEvenementExploits=<uninitialized>, strDir=5, strOss=95, sioLidsForStrIdCfd=<uninitialized>, sitSauveEtatSaisies=<uninitialized>, ssDtDeb=null, strSun=null, silActionAmeliorations=<uninitialized>, sioUtilisateurs=<uninitialized>, strCur=40E5174E8FAF449A82EEB7328647A127, strDtSup=null, strLoc=Marteau Cedex 03, sioFiltreStds=<uninitialized>, strNumOrdre=null, strCodPos=69399, silAcaOuvrages=<uninitialized>, silGroupeClients=<uninitialized>, sioStructures=<uninitialized>, strId=8, sioProfils=<uninitialized>, sioProfils_1=<uninitialized>, sioLidsForStrIdCcd=<uninitialized>, sitEqfCresRexes=<uninitialized>, sioLits=<uninitialized>, structure=null, strAdr2=BP 3109, typeStructure=com.rte.siquael.dao.entity.TypeStructure#CRES, strAdr1=3 bis, rue des Matelots, strFax=04XXXXXXXX, strVis=O, silPersonnesForStrIdApp=<uninitialized>, strTel=04XXXXXXXX}
org.hibernate.engine.jdbc.spi.SqlStatementLogger (SqlStatementLogger.java:109) - update SIT_EVENEMENT_QF set BCP_ID=?, CLI_ID_RESP=?, CPL_ID=?, CDF_ID_CONTR=?, EQF_AVT_INCID=?, EQF_BLOQUE=?, EQF_COD=?, EQF_COMMENT=?, EQF_COMMENTAIRE_RH=?, EQF_COMMENTAIRE_RHT=?, EQF_COMMENTAIRE_RJ=?, EQF_CONSTRUCTEUR=?, EQF_DATE_MISE_EN_SERVICE=?, EQF_DT=?, EQF_DT_CREAT=?, EQF_DT_MAJ=?, EQF_DT_MS=?, EQF_DT_MSCAL=?, EQF_ESR_NO=?, EQF_ESS_NO=?, EQF_IND_MARQ_LOC=?, EQF_IND_MARQ_NAT=?, EQF_IND_MARQ_REG=?, EQF_IND_RH=?, EQF_IND_RHT=?, EQF_IND_RJ=?, EQF_IND_TRAITEMENT=?, EQF_IRTSYST=?, EQF_MARQUAGE_DT=?, EQF_NO_EGA=?, EQF_OUV_LIB=?, EQF_OUV_NTN_LIB=?, EQF_REPRISE=?, EQF_RJE=?, EQF_TYPE_MATERIEL=?, EGA_COD=?, CDF_ID_GESR=?, CDF_ID_GESS=?, EQF_IND_ZONE=?, LID_ID=?, CDF_ID_MOTCLE=?, POS_ID=?, CDF_ID_RESP=?, STT_COD=?, CDF_ID_TESR=?, CDF_ID_TESS=? where EQF_ID=?
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction (JdbcTransaction.java:113) - committed JDBC Connection
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction (JdbcTransaction.java:126) - re-enabling autocommit
org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl (JdbcCoordinatorImpl.java:201) - HHH000420: Closing un-released batch
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl (LogicalConnectionImpl.java:246) - Releasing JDBC connection
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl (LogicalConnectionImpl.java:264) - Released JDBC connection
在eqfComment字段中有一个值,所以没有SqlStatement:
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:114) - Listing entities:
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.SioTypeLid{tliLib=Ligne simple, tliCod=L, sioLids=<uninitialized>}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.EvenementQf{eqfComment=t, eqfIndMarqNat=N, lid=com.rte.siquael.dao.entity.Lid#1476, eqfTypeMateriel=null, eqfEssNo=null, evtGrdAmpleur=null, eqfReprise=null, eqfIndRht=N, blocCoupure=null, eqfConstructeur=null, poste=null, sitPerturbations=[], eqfCod=17003430, eqfIndMarqLoc=O, indicateurZone=N, eqfCommentaireRh=null, eqfCommentaireRj=null, eqfDt=Sun Sep 10 07:08:09 CEST 2017, gesrId=null, eqfId=352082, eqfIrtsyst=N, sitCourtCircuits=[com.rte.siquael.dao.entity.CourtCircuit#337101], tessId=null, statut=E, sitAnomalies=[], eqfCommentaireRht=null, sitEvenementCbs=[], eqfIndTraitement=N, eqfEsrNo=null, motcleId=null, contrainteId=402, eqfRje=null, eqfMarquageDt=Mon Sep 11 16:08:09 CEST 2017, sitStatutAt=com.rte.siquael.dao.entity.SitStatutAt#E, eqfDtMs=0, eqfDtCreat=2017-09-11, eqfIndRj=N, clientId=null, eqfIndRh=N, eqfNoEga=null, sitEcartExploits=[], eqfAvtIncid=null, complementRegionaux=null, eqfDtMscal=212371812122000, eqfBloque=N, eqfOuvNtnLib=null, gessId=null, eqfDtMaj=Tue Sep 12 10:40:22 CEST 2017, eqfIndMarqReg=N, sitActionSuiviRexes=<uninitialized>, eqfOuvLib=null, eqfDateMiseEnService=null, tesrId=null, responsableId=463}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Poste{posIndiceCur=null, clients=<uninitialized>, blocCoupures=<uninitialized>, posAdr=Partenay les bonobonos, sioTypeSite=com.rte.siquael.dao.entity.TypeSite#P, posCoordonneeX=926619.18, posCoordonneeY=6514695.25, posEtat=Existant, posDtIn=1970-01-01, posId=1214, posNumNat=004, cdfIdTypProp=297, posDpde=1970-01-01, posDrfe=null, sioNiveauTensions=<uninitialized>, posDrde=1970-01-01, structureChargeeExploitation=com.rte.siquael.dao.entity.Structure#103, structureAdm=com.rte.siquael.dao.entity.StructureAdm#1312, commentaire=injection-soutirage , sioOuvrage=<uninitialized>, sioPays=com.rte.siquael.dao.entity.Pays#F, sioPsts=<uninitialized>, posCodNat=A.BAI, posDateModifInforef=2017-02-15, posDpfe=null, tranchesBt=<uninitialized>, complementRegionaux=null, posLibCrt=Partenay les bonobonos, posDtHs=null, posDtCre=1997-11-07, posDtMaj=2017-03-16, structureChargeeConduite=com.rte.siquael.dao.entity.Structure#8, posCur=13800B670A522054E043A3681E7C2054}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Poste{posIndiceCur=null, clients=<uninitialized>, blocCoupures=<uninitialized>, posAdr=Partenay les bonobonos, sioTypeSite=com.rte.siquael.dao.entity.TypeSite#P, posCoordonneeX=null, posCoordonneeY=null, posEtat=Existant, posDtIn=1974-01-01, posId=1215, posNumNat=145, cdfIdTypProp=304, posDpde=1989-01-01, posDrfe=null, sioNiveauTensions=<uninitialized>, posDrde=1989-01-01, structureChargeeExploitation=com.rte.siquael.dao.entity.Structure#103, structureAdm=com.rte.siquael.dao.entity.StructureAdm#1312, commentaire=null, sioOuvrage=<uninitialized>, sioPays=com.rte.siquael.dao.entity.Pays#F, sioPsts=<uninitialized>, posCodNat=A.BA5, posDateModifInforef=2014-12-12, posDpfe=null, tranchesBt=<uninitialized>, complementRegionaux=null, posLibCrt=Partenay les bonobonos, posDtHs=null, posDtCre=1997-11-07, posDtMaj=1998-05-29, structureChargeeConduite=com.rte.siquael.dao.entity.Structure#8, posCur=13800B670A512054E043A3681E7C2054}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Lid{sitAnomalies=<uninitialized>, sitEvenementQfs=<uninitialized>, lidNumNat=55S003300, sioTypeLid=com.rte.siquael.dao.entity.SioTypeLid#L, sitEvenementCbs=<uninitialized>, sitEvenementExploits=<uninitialized>, lidDtHs=null, lidDtIn=1974-01-01, sioTrancheTcds=<uninitialized>, structureChefFile=com.rte.siquael.dao.entity.Structure#103, lidDtMaj=2001-07-31, lidDtCre=1997-11-07, lidTer=N, commentaire=null, lidId=1476, silAcaOuvrages=<uninitialized>, sioOuvrages=<uninitialized>, sioNiveauTension=com.rte.siquael.dao.entity.SioNiveauTension#3, silActionCorrs=<uninitialized>, posteA=com.rte.siquael.dao.entity.Poste#1214, sioLits=<uninitialized>, posteB=com.rte.siquael.dao.entity.Poste#1215, sitCourtCircuits=<uninitialized>, lidCodNat=A.BAIL31A.BA5, structureChargeeConduite=com.rte.siquael.dao.entity.Structure#8, lidLib=63kV Partenay les bonobonos
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Structure{sioPostesForStrIdCep=<uninitialized>, strLib=GdP de Longefan, strCmp=0, sioPostesForStrIdCcp=<uninitialized>, clients=<uninitialized>, sitAnomalies=<uninitialized>, strDtCre=1992-02-01, silPersonnesForStrId=<uninitialized>, siqCodifications=<uninitialized>, ssDtFin=null, strIndiceCur=-, sitEvenementExploits=<uninitialized>, strDir=5, strOss=25, sioLidsForStrIdCfd=<uninitialized>, sitSauveEtatSaisies=<uninitialized>, ssDtDeb=null, strSun=S, silActionAmeliorations=<uninitialized>, sioUtilisateurs=<uninitialized>, strCur=D86AC36BE9AF4798937552AE34228317, strDtSup=null, strLoc=St Jean de Maurienne, sioFiltreStds=<uninitialized>, strNumOrdre=5, strCodPos=73300, silAcaOuvrages=<uninitialized>, silGroupeClients=<uninitialized>, sioStructures=<uninitialized>, strId=103, sioProfils=<uninitialized>, sioProfils_1=<uninitialized>, sioLidsForStrIdCcd=<uninitialized>, sitEqfCresRexes=<uninitialized>, sioLits=<uninitialized>, structure=com.rte.siquael.dao.entity.Structure#41, strAdr2=Cedex 1708, typeStructure=com.rte.siquael.dao.entity.TypeStructure#GdP, strAdr1=X, strFax=0479644607, strVis=O, silPersonnesForStrIdApp=<uninitialized>, strTel=0479640532}
org.hibernate.internal.util.EntityPrinter (EntityPrinter.java:121) - com.rte.siquael.dao.entity.Structure{sioPostesForStrIdCep=<uninitialized>, strLib=Lyon, strCmp=null, sioPostesForStrIdCcp=<uninitialized>, clients=<uninitialized>, sitAnomalies=<uninitialized>, strDtCre=1992-02-01, silPersonnesForStrId=<uninitialized>, siqCodifications=<uninitialized>, ssDtFin=null, strIndiceCur=-, sitEvenementExploits=<uninitialized>, strDir=5, strOss=95, sioLidsForStrIdCfd=<uninitialized>, sitSauveEtatSaisies=<uninitialized>, ssDtDeb=null, strSun=null, silActionAmeliorations=<uninitialized>, sioUtilisateurs=<uninitialized>, strCur=40E5174E8FAF449A82EEB7328647A127, strDtSup=null, strLoc=Lyon Cedex 03, sioFiltreStds=<uninitialized>, strNumOrdre=null, strCodPos=69399, silAcaOuvrages=<uninitialized>, silGroupeClients=<uninitialized>, sioStructures=<uninitialized>, strId=8, sioProfils=<uninitialized>, sioProfils_1=<uninitialized>, sioLidsForStrIdCcd=<uninitialized>, sitEqfCresRexes=<uninitialized>, sioLits=<uninitialized>, structure=null, strAdr2=BP 3109, typeStructure=com.rte.siquael.dao.entity.TypeStructure#CRES, strAdr1=3 bis, rue des Matelots, strFax=04XXXXXXXX, strVis=O, silPersonnesForStrIdApp=<uninitialized>, strTel=04XXXXXXXX}
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction (JdbcTransaction.java:113) - committed JDBC Connection
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction (JdbcTransaction.java:126) - re-enabling autocommit
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl (LogicalConnectionImpl.java:246) - Releasing JDBC connection
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl (LogicalConnectionImpl.java:264) - Released JDBC connection
对此有何想法?或者可能还有一些提示要进行调查?
答案 0 :(得分:2)
使用 @Temporal 注释,您可以存储时间,日期和时间戳
特别是, @Temporal(TemporalType.DATE)会忽略时间,例如,如果你有一个bean,它映射数据库表的字段只映射像DATE,你会看到以这种方式在db的时间 00:00:00
@Temporal(TemporalType.TIMESTAMP)时间不会被忽略。
注意: 有时当您在db上检查日期字段时,即使您以时间戳方式存储,也只看到日期,它通常取决于您的客户端,例如在sqldeveloper中,您可以启用或禁用在字段中显示日期时间的视图。 / p>