Persisting technology agnostic Java Model: JAXB vs. eCore [closed]

General Tech Technology & Software 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Technology & Software related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


Problem

Given a technology specific Java Model T, I want to have:

  • a technology agnostic model A to use in my code (i.e. the M in MVC).
  • a persistence mechanism P to store my model A.

Approach

Currently I have figured out some m.tuteehub.com/tag/options">options:

Option 1:

  • Manually create the classes for A
  • Manually create the code to translate T to A
  • Manually create an XSD of a third JAXB-Model J
  • Generate JAXB-Model-Classes from J
  • Manually create the code to translate A to J
  • Use JAXB to automatically save J
  • When loading all translations have to be created into the other direction manually.
  • Advantage: can't see one. Thats my question :)
  • Disadvantage: most developing effort of all Options.

Option 2:

  • Manually create an XSD of a JAXB-Model of A
  • Generate JAXB-Model-Classes for A
  • Manually create the code to translate T to A
  • Use JAXB to automatically save A
  • When loading the translations has to be created into the other direction manually.
  • Advantage: Low developing effort. A can be persisted directly.
  • Disadvantage: I read, that it's a bad Idea, to use JAXB-classes as modell. But I don't understand why.

Option 3:

  • Manually create the Model of A as an eCore-Model
  • Generate the classes of A from the ecore-Model
  • Manually create the code to translate T to A
  • Use eCore-resources to automatically save A
  • When loading the translations has to be created into the other direction manually.
  • Advantage: Low developing effort. A can be persisted directly.
  • Disadvantage: None?

Looking at the advantages and disadvatages, I it seems like I should definitly use eCore instead of JAXB.

Question

  • Is it really that clear, to use eCore? Or are there advantages/disadvantages I should also think about?
  • Is here an easier way to translate from the technology specific model T to the technology agnostic modell A. Currenly I have to implement A and the translation A <-> T myself. Some easier way would be nice.
profilepic.png
manpreet 2 years ago

You could use JAXB to convert your Model A to XML. This leverages the Java first aspect of JAXB instead if the schema first in your question.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.