Yes, but that's why it's dreaming: if Catalonia unilaterally left Spain, Spain would veto the Catalan entry in the EU (and not only Spain, any country with separatism, e.g. France/Corsica). That would force them indeed to put up walls and borders, develop a military, extend all the missing police force, and get systematically the short end of the stick in any trade deal because of its very little leverage.
An unilateral leave of Catalonia from Spain is not far from Brexit in shortsightedness.