This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Hibernate ENVERS AuditQuery returns only parts of the entity  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I use Hibernate ENVERS and want to query revisions by using a statement like this:


T is the entity class. In general the cods works find, BUT the result lists contain invalid entites because I've some fields (columns) in the entity that are not updateable and so not audited. E. g.:



So the result contains Tree entities with their name and id, but without the FIELD_PLANTAT and FIELD_PLANTBY value because these values are not updatable. In my opinion the entity is now unvalid because it has an Id but not all values that it should have when it is persistend.

I'm not sure why ENVERS behaves like this but is there may be an option to force ENVERS to load all data when loading a revision?

kind regards
Lars


 
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There might be such an option, but it would be wasteful. Why make repeated copies of columns whose values never change?

If I had to do something like this, I'd relate the envers query to the original table joining via the primary key. That way I'd get everything. I could even get more creative than that, since such a join would return both current and audit-point values of data, but anything more would complicate the system.
 
Lars Drießnack
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:...Why make repeated copies of columns whose values never change?...



Because you could have an request for a function that should roll back the whole entity to a previous version...

At the moment ENVERS doing nothing "wrong" but if you have something like this:
- a field which is nullable and value is not null
- a field which is nullable and value is null
- a field which is not nullable with a value
- a field which is not updateable but nullable and value is null
- a field which is not updateable but nullable and value is not null

With ENVERS at the moment you can get an revision entity with lots of null values and you could not know if it is null because it is really null or it is null because it is not updatable. In the second case you miss the real value.

The only way to get this information is using reflection and check the annotations of the class object of the entity and this is very poor.

I did not find a solution so far.

kind regards
 
Tim Holloway
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I won't say you're incorrect, because I haven't dissected those conditions in detail. Some of these conditions sound only possible if you have changed the attributes of the database table at some point, though, and I wouldn't expect envers to track schema modifications. And I wondered if some of them weren't a difference that effectively was no difference.

However, if you have an Entity column marked "updateable=false" and it gets updated within the application, that's not envers problem. It would mean a major failure of the core JPA functionality.

On the other hand, envers doesn't try to track out-of-band changes to the audited tables. If some other app updates a non-updateable column, then that's outside the scope of envers and you really should be doing a more centralized form of change tracking that audits all change sources.

I would hope that the audit table doesn't expect non-updateable columns to even be present. The audit table, after all, is an audit record, not an exact clone of the primary record. In either case you should be able to get the non-updateable value by joining with the primary table. And, again, I wouldn't expect envers to track changes made externally, so I can find no fault with it.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!