though he had gone to sea at the age of twelve , he had been fortunate enough to serve aboard first- or second-rate ships-of-the-line for the most part of his service , under wealthy captains who kept fine tables and entertained their officers regularly .