As others have implied, I would give up the three (or four) ranks deep battle formation. It may be historical, but it does not suit the game. The games are very much scaled down versions of historical battles (2000 men battles not 40,000 etc.). If battles lasted their true length and units got exhausted (and casualties/moral were lost more slowly), then I could see having depth would be useful - to rotate out men etc. But it really serves very little function in Total War games to have several melee units standing one in front of the other. If having depth means you are getting flanked then it is absolutely imperative you surrender depth - flanking is king in RTW.

Once you have abandoned that, your problem seems to be that the hastati don't perform as well as you thought. Looking at the unit stats, even with the +4 to the AI attack on hard, I find it hard to understand. Hastati are good early troops, with a very nice defence. You should have higher command generals that offset the AI +4 bonus, with each star giving you +1 to your attack.

A few things might help:

- screen with velites and archers, ie put them before, not behind your hastati. Surely that is the historical deployment? Friendly fire is horrible in RTW. Now, the velites may not do much directly against a barbarian infantry charge but I believe in TW, charge bonuses only work against the unit charged. The barbs charge your velites; they have to redirect to hit the hastati as the velites pull back. On medium, I have found the barbs sometimes halt in confusion and even retire under terrible fire when the velites give way to serried rows of hastati.

- put the hastati on fire at will (some folk say "guard" as well). That way they should get off a pila volley before impact and maybe a second after. The pila are great weapons but you tend not to have time to get a volley off if you try to manage it manually. The velite screening may help here - if it causes the barbs to slow down or withdraw, it gives more time for the pila. Don't worry about not charging - the hastati charge bonus is only +2; it's definitely worth surrendering to get the pila volley. When they are out of pila, alt+left click to charge with sword is of course sensible.

- forgive me for saying it, but your tactics sound a little passive. I would have thought that the Romans, through better discipline, were more able to outmaneouvre barbarians - so rather than just trying Saxon shieldwall tactics, holding with your hastati and then doing something more interesting (infantry or cav charge on the flanks, rely on archers from the flanks, lure away some of the enemy, spring an ambush etc) would seem to be called for. Contrary to what you are saying, the hastati are a decent anvil - but you do need a hammer (even if it is just more hastati coming in from the flanks).