bug #9683
closedAuto-initialize root bean
100%
Description
Currently only related objects are auto-initialized by the AbstractBean.beanAutoInitializers . The root bean itself is not initialized this way.
This leads to a situation where loading e.g. a field unit without any property path will throw an exception when fieldUnit.getTitleCache() is called outside the initializing transaction.
Related issues
Updated by Andreas Müller almost 3 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 50
Applied in changeset cdmlib|5348613baa59038220d4efd1e4a851e3ccdb6c58.
Updated by Andreas Müller almost 3 years ago
- Related to task #9678: Remove Derived- and FieldUnitFacadeCacheStrategies added
Updated by Andreas Müller almost 3 years ago
- Assignee changed from Andreas Müller to Andreas Kohlbecker
Updated by Andreas Müller almost 3 years ago
- Related to bug #7874: TeamOrPersonBase entity can become unusable due to replacement of the title caches on using getters added
Updated by Andreas Kohlbecker almost 3 years ago
- Status changed from Resolved to Feedback
- Assignee changed from Andreas Kohlbecker to Andreas Müller
I think the new method, which by the way is only used for test classes, is irritating:
public T loadProxy(int id);
The method name suggests that a proxy method is returned always. This is not the case as explained in the java doc of org.hibernate.Session.load(Class<T> theClass, Serializable id)
: "This method might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed."
This additional method, which is similar to other find*(..)
methods makes the Cdm*Dao-API unclear as there are already many similar methods.
Can't you use getSession().load()
in the test class directly or do you expect that the loadProxy()
will be used in non test classes frequently? In the latter case I suggest renaming it to just
public T load(int id);
Updated by Andreas Müller almost 3 years ago
- Assignee changed from Andreas Müller to Andreas Kohlbecker
Andreas Kohlbecker wrote:
I think the new method, which by the way is only used for test classes, is irritating:
public T loadProxy(int id);The method name suggests that a proxy method is returned always. This is not the case as explained in the java doc of
org.hibernate.Session.load(Class<T> theClass, Serializable id)
: "This method might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed."This additional method, which is similar to other
find*(..)
methods makes the Cdm*Dao-API unclear as there are already many similar methods.Can't you use
getSession().load()
in the test class directly or do you expect that theloadProxy()
will be used in non test classes frequently? In the latter cased I suggest renaming it it to justpublic T load(int id);
Yes, there is a need for this method if you want to attache an object to another one without initializing the object and without invoking cascade during save afterwards. This is for performance reasons and it is e.g. needed for imports.
We may discuss the label for the method. I first thought about loadWithoutInitializing but it is a bit long but maybe semantically better.
Purely "load(int)" has many disadvantages as all service.load(...) methods do explicitly initialize the return object(s) so it is very unexpected that only load(int) does not initialize (while eg. load(uuid) or load(int, null) do initialize.
Also the service.loadProxy(int) will always return a proxy except for the situation where it is used within another transaction. This is because it will only return a non-proxy if the object is already in the session which can only be the case if used within another transaction.
Updated by Andreas Müller almost 3 years ago
My comment was about the method in service. Maybe in dao it is slightly different as it is always used within a session. As this is not API we could more easily rename it to loadWithoutInitializing as long method names are maybe not so relevant here.
Updated by Andreas Kohlbecker almost 3 years ago
- Status changed from Feedback to Resolved
- Assignee changed from Andreas Kohlbecker to Andreas Müller
Ok, thank you for the explanation. I would prefer having the same method names in the DAP and service layer. We can keep loadProxy(int)
if the java doc of the methods are comprehensive enough to fully understand the implications of these methods. You could use the text of your comment above for extending the java doc.
Updated by Andreas Müller almost 3 years ago
- Status changed from Resolved to Feedback
- Assignee changed from Andreas Müller to Andreas Kohlbecker
- % Done changed from 50 to 90
I finally decided to rename the methods (in service and persistence) to loadWithoutInitializing as this is semantically more correct. Also I slightly adapted the javadoc.
So I guess we can close the ticket or are there any other open issues?
Updated by Andreas Kohlbecker almost 3 years ago
- Status changed from Feedback to Closed
- Assignee changed from Andreas Kohlbecker to Andreas Müller
- % Done changed from 90 to 100