I am able to create an entity object, set some default values and add it to the manager. Now I want to track the changes to it using manager.hasChanges(). For some reason, this always returns true. Should I be checking something else too when tracking newly created entities that are not in the database?
Breeze: Track changes on new object
223 Views Asked by jpo At
2
There are 2 best solutions below
0
DenisK
On
EntityManager treats an entity with EntityState.Added as a 'changed' entity. This is why HasChanges will always return true.
In this case, you should listen to EntityManager.entityChanged event to track changes.
See http://www.breezejs.com/sites/all/apidocs/classes/EntityManager.html#event_entityChanged
Related Questions in BREEZE
- InvalidArgumentException Unable to locate a class or view for component [input-error]
- php artisan breeze:install Execution error
- Facing some error while generating session for ICICI Breeze using Java SDK
- Laravel breeze nextjs and server side authentication request
- Error in production "Unable to locate file in Vite manifest: ..." inmy react routes (Breeze-react-laravel10-inertia)
- I have an issue with this tag . The dropdown componet from laravel breeze starter kit doen't work
- Laravel breeze can't work at safari 11 or safari 13
- toggle dark mode on laravel-breeze application
- my first API request is always null with vue, nuxt3 and typescript
- Issue with INSERT operation usine Breeze.Persistence.EFCore
- Calculate square root of covariance matrix in Scala
- Breeze Sharp - does it support a navigation property that is a TBH descendant of the parent entity type being queried?
- Fresh Laravel Install - Blank page after installing breeze
- laravel 10 starter template breeze and reactjs inertia problem
- Overwriting files when installing laravel Breeze
Related Questions in SINGLE-PAGE-APPLICATION
- How can I using useCookie in Nuxt 3 - Laravel API directory?
- Problem loading all of the resources for a single page application from REST API using Node.js and Express.js
- Angular Reusable Component with same selector
- Lost instance of my grpc in blazor webassembly when reload page
- Dynamically add pages in AEM Remote Spa
- Back Button in Onsen UI Navigator Triggering Validation Checks
- CSRF token from the 'X-Csrftoken' HTTP header incorrect
- Issue with Uploading File to Amazon S3 Bucket: File Saved as Blank
- Ensure USER is set to a value between 10000 and 20000
- ActionController::RoutingError (No route matches [GET] "/api/v1/contacts"): Rails + React
- Possible Bootstrap 5 bug when using data-bs-toggle="collapse" and offcanvas component. Fix?
- How to setup and configure service workers for a single page application to show an offline page
- Trying to make a single page application using window.onpopstate
- How do i securly save content in an vue SPA app
- Using both SPA and Blade view pages during authentication
Related Questions in ENTITYMANAGER
- Hibernate manage transaction on standalone application
- EntityManager - Truncate all data during test?
- How to properly use Spring AbstractEntityManagerFactoryBean.setEntityManagerInitializer method?
- @SqlResultSetMapping with ConstructorResult checks for all the field using BeanProperty
- Field repository in [package] required a bean named 'entityManagerFactory' that could not be found
- How to register dynamic JPA entities and repositories before Spring context loads using ByteBuddy?
- java transaction.rollback() not rollbacking the DB
- unit-test search method (querydsl) with mockito
- Spring JPA entity doesn't update when i use getReferenceId() in transactional function
- Why does entityManager.clear() fails my tests due to different date values even though I am not changing any of them?
- 'no transaction in use' when instantiating the SessionFactory manually and trying to persist via EntityManager
- Adding parameters to a @Subselect Entity using @FilterDef in Hibernate 6.3.1
- ReadOnly permissions to a Service in SpringBoot
- String boot filter Entity class on @entityscan
- SpringData JPA procedure not part of Transactional annotation
Related Questions in SELF-TRACKING-ENTITIES
- Entity Framework not changing EnityState on Update
- How to insert your Google Analytics tracking code in your Strikingly website with a free account?
- How to track disconnected entities over Web API
- Breeze: Track changes on new object
- Replacement of Self-tracking entities in Entity Framework 6
- Tracking changes to an entity framework object graph over multiple postbacks
- Using Entity Framework in a clustered enviroment (accessed remotely)
- Many queries and too much opening / closing of the same connection
- STE availability in Entity Framework 6
- Difference between Entity framework self tracking entities vs Unit of work
- Displaying list of self-tracking entities, filtering them by state
- EF4.x STE: Entity State not changed if SubItem is changed
- Attaching to context and keeping the entities objectstate
- I cant add an item to a Self Tracking Entity Collection with Navigation Properties
- Migrating from Self-Tracking Entities to DBContext
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
As soon as you 'Add' it to the EntityManager, by definition, it has changes because it is in an 'Added' state. To breeze 'hasChanges' means that it needs to be saved because it is 'different' from what was provided by your persistence service ( in this case the entity hasn't yet been 'saved').
What you can do is 'Attach' your entity to the EntityManager in an 'Unchanged' state.
In this case, any changes you make will work the way you want, BUT ...
Breeze will now consider your newly attached entity to already have been persisted and if you try to save it, then the save will fail because breeze will try to 'modify' the persisted entity instead of creating a new one.
If you really want to accomplish your request you will need to use 'attach' but also keep track of these entities and mark them 'added' before you attempt to save them.