| If we consider a plain JPA managed entity, you'd also have to either:
- Use a native query to fetch the data directly
- Use a mapping framework that can read the entity instance and convert it to some output.
So why an audited entity's history instances must be treated any differently? Your current solution takes advantage of (1) and will work. The only real disadvantage is that it could lead to portability issues across database vendors. I really believe you could leverage (2) here just as easily and remain portable. If you can't work around whatever Jackson issues you face, then perhaps adding one additional level of indirection could help. You could use something like Dozer to do a java-bean to java-bean mapping where you convert from the entity with a hierarchy / associations to a flattened java bean object that you could then very easily map to JSON using Jackson without the bidirectional problem. Wouldn't that work without changing the API and exposing the EntityMode.MAP data storage? |