∵A∩B={2,5},∴5∈A,A={2,4,5}.
由已知可得a3-2a2-a+7=5.
∴a3-2a2-a+2=0.∴(a2-1)(a-2)=0.∴a=2或a=±1.
(1)当a=2时,B={-4,5,2,25},A∩B={2,5}与题设相符;
(2)当a=1时,B={-4,4,1,12},A∩B={4}与题设矛盾;
(3)当a=-1时,B={-4,2,5,4},A∩B={2,4,5}与题设矛盾.
综上(1)(2)(3)知a=2,且A∪B={2,4,5}∪{-4,5,2,25}={-4,2,4,5,25}.