In few article it is mentioned that we should not fetch all column of a table. We should avoid Select * from table1 and write Select name, age, phone from table1.
Q1) Does this mean while writing HQL, we should not write from Table1?
Q2) I heard that some company uses stored procedure in their java code to fetch data, instead of writing select statement. Is this technique really efficient?
Q3) I heard that for a single application. Sometimes many database are used instead of having single database. Why is that so? Is this technique a good one?
Answer 1: Hibernate does not use
select *: It translatesselect from tabletoselect col1, col2, col3 ... from table1. Further, if you do not define a column to hibernate, it will not select it.Answer 2: My recommendation is to avoid using stored procedures. They are rarely in fact faster than queries, especially for simple data retrieval. There are many good reasons not to use them, which include 1) not portable, 2) impossible to debug, 3) can’t unit test, the list goes on
Answer 3: I would use one database and not split your data. It’s too hard to manage and you are adding more components to your system for no gain (also most systems use one database, so it can’t be that bad). Distributed databases however are a good idea.