I've been using Hibernate for a few years but have only used it with annotations, and by setting the connection parameters in my code.
Am I "missing something" by not using the XML files? Are there important capabilities available only in XML? Are there situations or patterns where it makes sense to use the XML?
Use updatable=false in Hibernate to avoid updating the column.
One way to do this is using JPA XML configuration to override the existing class annotations.
@Column. Let's start with the @Column annotation. It is an optional annotation that enables you to customize the mapping between the entity attribute and the database column.
@Table annotation specifies the table name where data of this entity is to be persisted. If you don't use @Table annotation, hibernate will use the class name as the table name by default. @Id annotation marks the identifier for this entity.
I think it's pretty safe to say that you're not missing out on anything.
If there are any capabilities in XML that can't be represented in attributes (and I believe there are some rare cases) then you still have the option to use [RawXml] and write the XML in the attribute. So you can't possibly miss out on any functionality.
It might make sense to use XML if you have enough programmers in your team who simply prefer to manage separate files or if there is a genuine need to edit xml mappings on the fly. Xml mapping files are probably easier to manipulate for very complex mapping and they can contain useful information (comments on fetching strategies etc).
There is also the issue of architecture, where some people argue that separating the mapping into XML files provides a better separation between business-related code and instructions on how it is persisted.
Annotations are a great way to quickly configure Hibernate. But one of the key features of OR mappers like Hibernate is that you keep your domain model "persistence ignorant" your objects don't need to know anything about where and how they are persisted. Some may argue that using annotations breaks that. And in situations where persistence is just one of many concerns it makes sense to keep things separate.
Another reason can be that domain objects are persisted differently in different situations, you can have multiple databases used by one application or even more applications that use the same domain model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With