1

I have a project which includes dto classes from another project which I can't modify. I wish to persist their data but extending or embedding them requires me to modify them by adding appropriate annotations.

Is the best solution here to use xml, or it there someway I've missed to tell hibernate to persist an embedded or composed class without annotating the other project's class?

1 Answer 1

2

You should somehow provide mapping information to Hibernate. There are two ways:

  • annotations
  • XML mappings

Since you want to use classes from another project but can't annotate them, the only option is to use XML mappings.

However I would suggest implementing your own persistence and conversion layers, i.e. obtain DTO -> convert to entity -> persist. It gives the following advantages:

  1. Better DB schema. DTOs may not be adapted well for persistence.
  2. More control. Changes done in another project may break/impact persistence. Converters are usually easier to fix.
Sign up to request clarification or add additional context in comments.

1 Comment

I think your argument makes a lot of sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.