More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Q1510. If we would like to load just the mapping id for the mapped entity, how can we accomplish that.
For example -
Employee entity is mapped to department entity through department id. We want that when we load employee.getDepartment().getDepartmentId(), it shouldn't load the complete department object but just the Id.
Q1511. If we would like to load just the mapping id for the mapped entity in some cases and whole entity in some cases, because we would like to lazily initialize the dependent entity in some case and not load the entity at all in some case, how can we accomplish that.
For example -
Employee entity is mapped to department entity through department id. We want that when we load employee.getDepartment().getDepartmentId(), it shouldn't load the complete department object but just the Id.
Ans. The error states that Hibernate is not able to initialize proxy / dependent entity objects as there is no session or transaction present. Very likely we are trying to load the dependent entities lazily but the call to dependent object property is not wrapped within the session or transaction.
Help us improve. Please let us know the company, where you were asked this question :
Q1513. If you are given choice to avoid LazyInitializationException using any of the following measures, which are the ones you will choose and why ?
1. Set lazy=false in the hibernate config file.
2. Set @Basic(fetch=FetchType.EAGER) at the mapping.
3. Make sure that we are accessing the dependent objects before closing the session.
4. Force initialization using Hibernate.initialize
Ans. Override the behavior of collection class to sort the list upon each element addition. Though it's not recommended as list are sorting heavy data structures.
List<MyType> list = new ArrayList<MyType>() {
public boolean add(MyType mt) {
super.add(mt);
Collections.sort(list, comparator);
return true;
}
};
Help us improve. Please let us know the company, where you were asked this question :
Ans. Substitutability means that the type of the variable does not have to exactly match with the type of the value assigned to that variable. For example - Object reference of Parent object can hold derived object.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Abstract methods are the methods that need to be overridden in the derived class ( either as implementing method or again abstract method ) so it's not only allowed but its required to override abstract method in the derived class.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes, but in that case the derived class itself should be abstract. We cannot have an object of a class without definition for the method which has been declared abstract in the parent.
Help us improve. Please let us know the company, where you were asked this question :
Q1529. What is the difference between TimeBasedRollingPolicy and SizeBasedTriggeringPolicy within Log4j ? Can we use both together and What would that mean ?
Ans. TimeBasedRollingPolicy enables rolling of logs based on the time / days whereas SizeBasedTriggeringPolicy enables rolling of logs based on size cap.
Yes we can use both together. In that case Logs will be rolled in case any of the condition is met i.e after the interval or if the size is reached.
Help us improve. Please let us know the company, where you were asked this question :