Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:11:11+00:00 2026-06-06T22:11:11+00:00

I’m currently migrating my project from Hibernate HBM Mappings to Annotations. Everything was easy

  • 0

I’m currently migrating my project from Hibernate HBM Mappings to Annotations.
Everything was easy as far as i dealt with small classes.
But I have same huge classes and i try to mix both mapping and annotations for this class. I read that this was possible by using the hibernate property “hibernate.mapping.precedence” and setting it to “class, hbm” instead of “hbm, class”. (see: In Hibernate: is it possible to mix Annotations and XML configuration for an Entity?)

For example I have the following Document class:

@Entity
@Table(name="DOCUMENT")
public class Document  {
   @Column(name="DESCRIPTION")
   private String description;
}

and the following Document.hbm.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">    
<hibernate-mapping>
  <class name="Document" table="DOCUMENT" >
    <id name="id" column="DOCUMENT_ID" type="long" />
  </class>
</hibernate-mapping>

In my hibernate.cfg.xml file I put:

<property name="hibernate.mapping.precedence">class, hbm</property>
<mapping class="Document"/>
<mapping resource="Document.hbm.xml"/>

My problem is that:
– if I put “class, hbm” for the precedence then I have ONLY my annotations in class Document
– if I put “hbm, class” then I have ONLY my mappings in the hbm ressource

Does anyone knwo if there is a way to have both Annotations and HBM mappings ?

Thanks

Kamran

PS: I use : Hibernate 4.1.4 and Spring Framework 3.1.1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:11:15+00:00Added an answer on June 6, 2026 at 10:11 pm

    You can’t mix them for the same class. At the end of section 1.2 of hibernate annotations:

    You can mix annotated persistent classes and classic hbm.cfg.xml declarations with the same SessionFactory. You can however not declare a class several times (whether annotated or through hbm.xml). You cannot mix configuration strategies (hbm vs annotations) in an entity hierarchy either.

    To ease the migration process from hbm files to annotations, the configuration mechanism detects the mapping duplication between annotations and hbm files. HBM files are then prioritized over annotated metadata on a class to class basis. You can change the priority using hibernate.mapping.precedence property. The default is hbm, class, changing it to class, hbm will prioritize the annotated classes over hbm files when a conflict occurs.

    Using annotations and hbm files is declaring a class two times. Therefore, one will be prioritized over the other in a class to class basis (class to class basis means that for each class, only the hbm file or the annotations are used).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.