[forge-users] Any recommended strategy for Angular/REST scaffolds with JPA bidirectional relationships

forge-users at lists.jboss.org forge-users at lists.jboss.org
Thu Nov 27 02:38:42 EST 2014


Well, we recommend using the DTO strategy for this. Even with @JSONManagedReference and @JSONBackReference annotateds on JPA entities, you would run into some issues, especially when updating the entities via a HTTP PUT. That's why we recommend using DTOs.

For now, with the DTO strategy, Forge supports creation of a 2-level DTO hierarchy where no cycles will be created in the DTO graph, thus eliminating the need for Jackson annotations, while supporting updates to the entities in a limited form. For every DTO that it creates, Forge will traverse the corresponding JPA entity and map it's properties; it will also traverse the relationships in the JPA entities and create nested DTOs to represent the related entities. It does not however traverse any further, primarily to break any cyclic or bi-directional relationships. The constructed DTOs contain logic to assemble the JPA entity back from the contents of the DTO, and also update any object references (so it gets past the problems you run into with some of the Jackson annotations); it does not contain logic to update properties of referenced JPA entities (say you delink B from A, then the resource for A will have no issues in delinking the objects, but if you update B and expect the REST resource for A to transitively update B, then this is not supported).

If you need additional strategies to be built, we can help with that.

Posted by forums
Original post: https://developer.jboss.org/message/911686#911686



More information about the forge-users mailing list