Buggy code:
public class Metadata { private Map < String , Map < String , PageInfo > > pages ; private Map < String , Map < String , FileInfo > > files ; public Metadata ( ) { } public void queryMetadata ( Set < PageInfo > pages , GregorianCalendar start , GregorianCalendar end ) { try { for ( PageInfo page : pages ) { storePage ( page ) ; queryPageInfo ( page . getLang ( ) , page . getPageId ( ) , page ) ; queryRevisionList ( page . getLang ( ) , page . getPageId ( ) , page , start , end ) ; queryFileList ( page . getLang ( ) , page . getPageId ( ) , page ) ; } Set < FileInfo > fileSet = new HashSet < > ( ) ; for ( String lang : files . keySet ( ) ) { fileSet . addAll ( files . get ( lang ) . values ( ) ) ; } for ( FileInfo file : fileSet ) { queryFileInfo ( file . getLang ( ) , file . getTitle ( ) , file ) ; } List < Map < Page , Object > > pageRecords = new LinkedList < > ( ) ; List < Map < File , Object > > fileRecords = new LinkedList < > ( ) ; List < Map < Revision , Object > > revisionRecords = new LinkedList < > ( ) ; List < Map < PageFile , Object > > pageFileRecords = new LinkedList < > ( ) ; for ( PageInfo page : pages ) { Map < Page , Object > pageRecord = new HashMap < > ( ) ; pageRecord . put ( LANG , page . getLang ( ) ) ; pageRecord . put ( PAGE_ID , page . getPageId ( ) ) ; pageRecord . put ( TITLE , page . getTitle ( ) ) ; pageRecord . put ( SIZE , page . getSize ( ) ) ; pageRecord . put ( LAST_REV_ID , page . getLastRevisionId ( ) ) ; pageRecords . add ( pageRecord ) ; } PAGE . insertOrIgnoreBatch ( pageRecords ) ; List < Map < Page , Object > > updatedPages = PAGE . retrieveAll ( ) ; Map < String , Integer > pageIdMap = new HashMap < > ( ) ; for ( Map < Page , Object > updatedPage : updatedPages ) { pageIdMap . put ( ( ( ( updatedPage . get ( LANG ) ) + "//" ) + ( updatedPage . get ( PAGE_ID ) ) ) , ( ( Integer ) ( updatedPage . get ( ID ) ) ) ) ; } for ( FileInfo file : fileSet ) { Map < File , Object > fileRecord = new HashMap < > ( ) ; fileRecord . put ( File . LANG , file . getLang ( ) ) ; fileRecord . put ( File . TITLE , file . getTitle ( ) ) ; fileRecord . put ( File . SIZE , file . getSize ( ) ) ; fileRecords . add ( fileRecord ) ; } FILE . insertOrIgnoreBatch ( fileRecords ) ; List < Map < File , Object > > updatedFiles = FILE . retrieveAll ( ) ; Map < String , Integer > fileIdMap = new HashMap < > ( ) ; for ( Map < File , Object > updatedFile : updatedFiles ) { <START_BUG> fileIdMap . put ( ( ( ( updatedFile . get ( File . LANG ) ) + "//" ) + ( updatedFile . get ( File . TITLE ) ) ) , ( ( Integer ) ( updatedFile . get ( ID ) ) ) ) ; <END_BUG> } for ( PageInfo page : pages ) { int pageId = pageIdMap . get ( ( ( ( page . getLang ( ) ) + "//" ) + ( page . getPageId ( ) ) ) ) ; for ( RevisionInfo revision : page . getRevisions ( ) ) { Map < Revision , Object > revisionRecord = new HashMap < > ( ) ; revisionRecord . put ( Revision . PAGE_ID , pageId ) ; revisionRecord . put ( REV_ID , revision . getRevId ( ) ) ; revisionRecord . put ( TIMESTAMP , revision . getTimestamp ( ) . getTimeInMillis ( ) ) ; revisionRecords . add ( revisionRecord ) ; } for ( FileInfo file : page . getFiles ( ) ) { int fileId = fileIdMap . get ( ( ( ( file . getLang ( ) ) + "//" ) + ( file . getTitle ( ) ) ) ) ; Map < PageFile , Object > pageFileRecord = new HashMap < > ( ) ; pageFileRecord . put ( PageFile . PAGE_ID , pageId ) ; pageFileRecord . put ( FILE_ID , fileId ) ; pageFileRecords . add ( pageFileRecord ) ; } } REVISION . insertOrIgnoreBatch ( revisionRecords ) ; PAGE_FILE . insertOrIgnoreBatch ( pageFileRecords ) ; } catch ( SQLException ex ) { LogHandler . log ( this , ERROR , ex ) ; } } private void storePage ( PageInfo page ) { } private void storeFile ( FileInfo file ) { } private PageInfo getOrCreatePage ( String lang , String pageId ) { } private FileInfo getOrCreateFile ( String lang , String title ) { } private PageInfo getPage ( String lang , String pageId ) { } private FileInfo getFile ( String lang , String title ) { } private void queryPageInfo ( String lang , String pageId , PageInfo page ) { } private List < Map < String , Object > > queryFileListWorker ( String lang , String pageId , String cont ) { } private void queryFileList ( String lang , String pageId , PageInfo page ) { }

Fix:
fileIdMap . put ( ( ( ( updatedFile . get ( File . LANG ) ) + "//" ) + ( updatedFile . get ( File . TITLE ) ) ) , ( ( Integer ) ( updatedFile . get ( File . ID ) ) ) ) ;