I don't think Barnabas caused David's dream either. However, an argument could be made that if he did, the intent wasn't to expose his secret to David but to discredit him in a similar way to how Barnabas will be going about discrediting David in a future episode (involving a certain beloved prop on a stick
).
I believe the most likely cause is that David's own intuitive powers brought about the dream. His experience in the mausoleum coupled with Barnabas' overreaction to it have caused David's unconscious mind to stumble upon the truth that Barnabas is indeed one of the undead - and David's pyschic intuition warned him about Julia, though he wasn't sure just who the woman was until the incident with Julia and her medallion actually took place. That scenario seems perfectly in keeping with David's character and the intuitive abilities he's thus far exhibited on the show. And in that way the writers are going about things in the perfect manner...
Changing the subject, I love the following two screen captures from this episode. Talk about a study in contrasts!
Julia supremely confident her hypnosis techniques will save the day:
Then disheartened when she fails: