mailwal

Pick the one you like ... or use both

Thorben

Hey,

In today's email, I want to give you a quick answer to a common question about Hibernate's mapping definitions.

You can define your mapping in an XML file or annotate your entity classes.

People often ask me which approach is better and if they can mix them.

The short answers are:

  1. Both are fine, but I like annotation-based mappings better. They are easier to read, and I have all the information in the same place.

  2. Yes, you can mix them, even for the same class. If there's a conflict, the XML-based mapping wins.
    This is great if you need to adjust your mappings for different installations or when you want to migrate from XML- to annotation-based mapping definitions.

If you're looking for more detailed answers, please read this article.

Speak soon,

Thorben

  1. Check out the latest tutorials on the blog.
    Stay up to date with the latest releases and features in the Java persistence world. Read the blog.

  2. Watch my tutorials on YouTube.
    You prefer videos over written content? Then my YouTube channel is the right place for you.

  3. Get my Hibernate Tips ebook.
    The ebook is packed with ready-to-use solutions to help you solve your next Hibernate problem even quicker. Get it here.

  4. Join the Persistence Hub.
    The Persistence Hub teaches you everything you need to know on your journey to becoming a Java persistence expert. Get access to video courses, Expert Sessions with amazing guests, monthly Java Persistence News, and more. Become a member.

Thorben Janssen, Elser Bruch 63, 33106, Paderborn, Germany