Modify such that accessing an unloaded property throws a LazyInitialisationException. This includes ToMany collections that where previously initialised as empty collections (that didn't lazy load).
This change brings the disableLazyLoad behaviour in line with the unmodifiable behaviour.
It does mean that the use case of bulk mapping from entities to DTOs via something like MapStruct will no longer work nicely (mapping nulls and empty lists versus LazyInitialisationException).
Entities without *any* relationships can support "sharable instances" with bean caching. This change restores that and uses unmodifiable instances (rather than the old ReadOnly).
Currently, for a query to get shared instances it now needs to explicitly use setUnmodifiable(true) where as before it defaulted to shared instances so that is a behaviour change.
Additionally, bean cache queries were not honouring setUnmodifiable(true) and with these changes they now do.
- Query Cache now holds unmodifiable collections
- Can no longer have readOnly=false with queryCache=true
- Reference beans now also honor unmodifiable
- Effectively no longer does bean cache lookup for reference beans (which it defaulted to when cacheSharableBeans true, e.g. Country entity bean)
The test was using field access??? when that isn't valid unless we specifically turn on enhancement to support that.
Using proper method access though stops the test from failing.
So we can no longer dynamically change the Clock being used and instead for testing purposes need to create the Database with a test clock instance as needed.
Refer to the ExtendedServerTest for an example
- Adds new exceptions UnloadedPropertyException and UnmodifiableEntityException
- Change InterceptReadOnly to use these exception instead of IllegalStateException
- Change collections BeanSet, BeanList, BeanMap from using IllegalStateException to UnsupportedOperationException [to bring these in line with JDK unmodifiable collections]
* ADD: Testcase for showing nested transaction with batch-mode not flushing batch on commit
* Update test only - TestNestedTransaction.test_txn_nestedWithInnerBatch()
Update the test to show that we desire the nested transaction changes to be "visible" after a commit regardless of flushOnQuery etc
* #3564 Fix for nested transaction with batch-mode does not flush
- Adds flush() into ScopeTrans.commitTransaction()
- Related fixes in DefaultServer execute() and executeCall() where it was performing extra unnecessary nesting on PersistenceException
* Touch
---------
Co-authored-by: Jonas Pöhler <jonas.poehler@foconis.de>
As HelpScopeTrans isn't in an exported package it's use fails with an error in module path. This adds AOPTransactionScope in the exported package io.ebean.plugin and moves the required methods from SpiEbeanServer to SpiServer to support this move.
This also requires an associate change in ebean-agent to support this feature which will be in ebean-agent 14.9.0.
Internally in CQueryBuilder only use query.setSelectId(); for findCount when the entity bean has a @Id property [which it doesn't strictly need and likely won't have for view based entities]
* #3552 Column alias required for SQL Server + findCount + distinct
- Modifies CQueryBuilder with the main fix which is to use the database platform selectCountWithColumnAlias for all distinct queries [and later disable it for single column case]
- Modifies SqlTreeBuilder because we need to NOT use the column alias for the count distinct SINGLE COLUMN case. So change here to:
- build the root SqlTreeNode first as part of constructor
- use rootNode.isSingleProperty() to NOT use column alias for the single column case
- Hence need to initialise DefaultDbSqlContext AFTER the root SqlTreeNode
- Modifies DefaultDbSqlContext with no effective change, just columnIndex++ ONLY when we are actually using column alias
- Modifies H2Platform to also use selectCountWithColumnAlias true
* #3552 selectCountWithColumnAlias true for MariaDB and MySql
Plus fix TestRowCount for Oracle platform
Although this is ok, makes me think that another option is just to have query.setReadOnly(true)
to mean ... readOnly + disableLazyLoad + error reading unloaded property or collection. As in,
readOnly true without these extra things does not that good [as in the existing readOnly does
not seem very good/safe/useful to use].