ravivasamsetty (1) [Avatar] Offline
#1
Hi All,

I started reading Java persistence with Hibernate and one particular side bar in chapter 3 made me think a bit.
That particular Side bar talks about attribute and method visibility.

Author criticized the use of package visibility and I for one thought package visibility has a place.
Some external dependencies like EntityManager (EM) in a dao should be declared package visible so that while testing it would be easier to replace it with whatever I want. (Mock or use EntityManagerFactory to get EM)

My question is, Did author meant package visibility is bad within an Entity? or Was my understanding of testability improvement with usage of package visible dependencies off?
Christian Bauer (56) [Avatar] Offline
#2
Package visibility is bad, period, unless your system must enforce security policies. I don't understand what you are saying about testing and package visibility and I'm not sure I want to discuss this any further.