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 7727821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:33:33+00:00 2026-06-01T05:33:33+00:00

Got classical Hibernate problem: Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: entry.Authority

  • 0

Got classical Hibernate problem:

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: entry.Authority column: username (should be mapped with insert="false" update="false")

users.hbm.xml:

<class name="entry.User" table="users">
    <property name="username" column="username"/>
    <set name="authorities" table="authorities" lazy="false" cascade="all">
        <key column="username" not-null="true"/>
        <one-to-many class="entry.Authority"/>
    </set>

authorities.hbm.xml:

    <class name="entry.Authority" table="authorities">
        <id name="id"/>
        <property name="username" column="username"/>
    </class>

Tried classical solution:

<property name="username" column="username"  insert="false" update="false"/>

Got:

java.sql.BatchUpdateException: Field 'username' doesn't have a default value

Why I can’t specify username twice in .xml?
As I understand this declaration <property name="username" column="username"/> relates to User and <key column="username" not-null="true"/> relates to Authorities
.So why they clash?
How can it be fixed with minimum invasion?

EDITED:

    <class name="entry.User" table="users">
        <id name="id">
            <generator class="increment" />
        </id>
        <property name="username" column="username"/>     
        <set name="authorities" table="authorities" lazy="false" cascade="all" inverse="true">
            <key column="username" not-null="true"/>
            <one-to-many class="entry.Authority"/>
        </set>
...

and

<class name="entry.Authority" table="authorities">
    <id name="id"/>
    <property name="username" column="username"/>
    <property name="authority" column="authority"/>
    <many-to-one name="user" class="entry.User">
             <column name="username"/>
     </many-to-one>
</class>
  • 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-01T05:33:35+00:00Added an answer on June 1, 2026 at 5:33 am

    With the key definition in users.hbm.xml <key column="username" not-null="true"/> you already handle the column username in Authorities. The line <property name="username" column="username"/> in authorities.hbm.xml is superfluous, even if used in many-to-one. Every time you load/update or insert the instances of Authorities via Users, the field is handled automatically by Hibernate. If you define the field also in authorities.hbm.xml then it is set twice – that’s why you got your error message.

    If you by some special reasons really want to have the username also in authorities.hbm.xml, then you have to specify insert/update = false (as you already did) and a default value to avoid your error message (even if the default never is used). For example

    <property name="username" insert="false" update="false">
      <column="username" default="anyValue"/>
    </property>
    

    But I would simply recommend this:

    <class name="entry.Authority" table="authorities">
      <id name="id"/>
      <property name="authority" column="authority"/>
      <many-to-one name="user" class="entry.User">
             <column name="username"/>
       </many-to-one>
    </class>
    

    Added after your comment:

    Now I see a problem in your new mapping: the <key> element has to reference to the key of the parent table, and that is not the case. The key in the Users table is id, but you use a normal property Username as the foreign key in Authority. There are two possibilities to resolve this:

    1) You make Username the key of Users (drop column id and define the key in Users as

    <id name="username">
     <column="username"/>
    </id>
    

    (I’m not sure if in this case in new instances of Authority hibernate will set the member username automatically or if you have to do it manually.)

    new: Here is the complete mapping (not tested):

    <class name="entry.User" table="users">
      <id name="username" type="String">
        <column="username"/>
      </id>
      <property name="password" column="password" type="String"/>
      <property name="enabled" column="enabled" type="boolean"/>
    
      <set name="authorities" table="authorities" lazy="false" cascade="all" inverse="true">
        <key column="username" not-null="true"/>
        <one-to-many class="entry.Authority"/>
      </set>
    </class>
    

    2) You make id the foreign key in Authority:
    In users.hbm.xml

    <key column="id" not-null="true"/>
    

    , and in authority.hbm.xml you replace the column username with

    <property name="userId" column="userId"/>
    

    You also have to modify the database table then.

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

Sidebar

Related Questions

i have got the following problem: I want to create a new Liferay Theme
I've got a problem with textarea's in Google Chrome. I'm using classic ASP, but
I 'm new to classic asp and got a problem with the dictionary object.
I'll keep this simple: So, if I've got the classic three environments (dev/test/production), should
I've got a classical ASP website in which I store some information inside the
I got a classic multipart form with spring mvc 3 which works fine :
We've got a classic ASP application that is putting out some very large reports,
I've got an old classic ASP site that connects to a local sql server
In Classic ASP, how do you detect on that the page got control via
I've got the unpleasurable task of working on a Classic ASP site (VBSCRIPT) and

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.