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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:10:33+00:00 2026-05-19T03:10:33+00:00

We are trying to use Hibernate with a database that uses a lot of

  • 0

We are trying to use Hibernate with a database that uses a lot of composite keys and it’s been causing us a lot of headaches.
Unfortunately, we can’t change the schema so we have to do a lot of additional mapping betwen our fields. We are restricted to using JPA 1.0 and Hibernate 3.3.

The biggest problem
we’ve had so far is to do with a one-to-one association between two entities using a composite key of 2 values, where the tables have different names
for these columns (the DB has a naming convention of having a table-specific prefix on each column.)

Whenever we perform our query, we get this exception:

Caused by: org.hibernate.TypeMismatchException Provided id of the wrong type for class com.business.entity.InvestorIssuerEmailEntity.  
Expected: class com.business.entity.InvestorIssuerEmailEntityPK, got class com.business.entity.InvestorIssuerEntityPK; 

The two classes for these tables, InvestorIssuerEntity and InvestorIssuerEmailEntity, have an optional @OneToOne assocation
(in some cases InvestorIssuer has no matching record in InvestorIssuerEmail):

@IdClass(InvestorIssuerEntityPK.class)
@Table(name = "T090_INVESTOR_ISSUER")
@Entity
InvestorIssuerEntity
    @Column(name = "T090_091_INVESTOR_ID", nullable = false, insertable = true, 
updatable = true, length = 18, precision = 0)
    @Id
    private Long investorId;

    @Column(name = "T090_102_ISSUER_ID", nullable = false, insertable = true, 
updatable = true, length = 18, precision = 0)
    @Id
    private Long issuerId;

(other fields omitted)

    @OneToOne(optional = true)
    @JoinColumns(value = {
            @JoinColumn(name="T090_091_INVESTOR_ID", referencedColumnName = "T284_INVESTOR_ID", nullable = false, insertable = false, updatable = false),
            @JoinColumn(name = "T090_102_ISSUER_ID", referencedColumnName = "T284_ISSUER_ID", nullable = false, insertable = false, updatable = false)
    })
    @NotFound(action = NotFoundAction.IGNORE)
    private InvestorIssuerEmailEntity investorIssuerEmail;

... 

InvestorIssuerEntityPK 
    @Id
    @Column(name = "T090_091_INVESTOR_ID", nullable = false, insertable = true, 
updatable = true, length = 18, precision = 0)
    private Long investorId;

    @Id
    @Column(name = "T090_102_ISSUER_ID", nullable = false, insertable = true, 
updatable = true, length = 18, precision = 0)
    private Long issuerId;

...

@IdClass(InvestorIssuerEmailEntityPK.class)
@Table(name = "T284_INVESTOR_ISSUER_EMAIL")
@Entity
InvestorIssuerEmailEntity
    @Column(name = "T284_INVESTOR_ID", nullable = false, insertable = true, 
updatable = true, length = 18, precision = 0)
    @Id
    private Long investorId;

    @Column(name = "T284_ISSUER_ID", nullable = false, insertable = true, 
updatable = true, length = 18, precision = 0)
    @Id
    private Long issuerId;

...

InvestorIssuerEmailEntityPK 

    @Column(name = "T284_INVESTOR_ID", nullable = false, insertable = true, 
updatable = true, length = 18, precision = 0)
    @Id
    private Long investorId;

    @Column(name = "T284_ISSUER_ID", nullable = false, insertable = true, 
updatable = true, length = 18, precision = 0)
    @Id
    private Long issuerId;  

I’ve tried to get around the Type Mismatch problem by using the same class as the @EmbeddableId for the two entities, and then using @AttributeOverrides, like this:

@Id
@EmbeddedId
@AttributeOverrides({
        @AttributeOverride(name = "investorId",
                column = @Column(name = "T284_INVESTOR_ID", nullable = false, insertable = true, updatable = true, length = 18, precision = 0)),
        @AttributeOverride(name = "issuerId",
                column = @Column(name = "T284_ISSUER_ID", nullable = false, insertable = true, updatable = true, length = 18, precision = 0))
})
private InvestorIssuerId investorIssuerId;

I only did the change for these two entities though, still using the @IdClass approach for the other entities (Is it a case of only using @IdClass OR @EmbeddableId for your entities, not both?)

We ended up getting other issues like “Repeated column in mapping for entity”, so we’ve reverted to this approach to see if there’s other workarounds to this.

Does anyone have any solutions to get around this problem? I’ve looked around StackOverflow but haven’t come across any cases where the composite keys used in the association have different names.

Note:
Even after trying the suggestion below, we still get this error: org.hibernate.MappingException: Repeated column in mapping for entity: com.business.entity.InvestorIssuerEntity column: T090_091_INVESTOR_ID (should be mapped with insert=”false” update=”false”)

I even removed ALL associations from InvestorIssuerEntity and still got the same problem. The error only went away when I removed the @Column annotation in the composite key class. Of course, the queries didn’t work because the investorId wasn’t mapped! I don’t understand where Hibernate was finding the “Repeated column in mapping”, since I’d already removed every mention of T090_091_INVESTOR_ID else except for the composite key.

We have other associations in InvestorIssuerEntity that do a join on the same primary keys, but the associated entities also have additional columns in their composite keys. Once you use @EmbeddedId, are you supposed to use them for all entities? We still use @IdClass for the others classes. But then how does that cause a “repeated column” anywhere?

  • 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-05-19T03:10:34+00:00Added an answer on May 19, 2026 at 3:10 am

    It seems I got a working solution for your case:

    @Entity
    public class InvestorIssuerEntity {
        @EmbeddedId 
        private InvestorIssuerEntityPK investorIssuerEntityPK;
    
        @OneToOne(optional=true, mappedBy="investorIssuerEntity")
        private InvestorIssuerEmailEntity investorIssuerEmailEntity;
    }
    
    @Entity
    public class InvestorIssuerEmailEntity {
        @EmbeddedId @AttributeOverrides({
            @AttributeOverride(name="investorId", column=@Column(name="T02_INV_ID")),
            @AttributeOverride(name="issuerId", column=@Column(name="T02_ISS_ID"))
        })
        private InvestorIssuerEntityPK investorIssuerEntityPK;
    
        @OneToOne(optional=true) @PrimaryKeyJoinColumns({
            @PrimaryKeyJoinColumn(name="T02_ISS_ID", referencedColumnName="T01_ISS_ID"), 
            @PrimaryKeyJoinColumn(name="T02_INV_ID", referencedColumnName="T01_INV_ID")
        })
        private InvestorIssuerEntity investorIssuerEntity;
    }
    
    @Embeddable
    public class InvestorIssuerEntityPK implements Serializable {
        private static final long serialVersionUID = -1176248537673293674L;
    
        @Column(name="T01_INV_ID")
        private Long investorId;
    
        @Column(name="T01_ISS_ID")
        private Long issuerId;
    }
    

    It generates the following DDL, which seems to be what you are looking for:

    create table InvestorIssuerEmailEntity (
        T02_INV_ID bigint not null,
        T02_ISS_ID bigint not null,
        primary key (T02_INV_ID, T02_ISS_ID)
    )
    
    create table InvestorIssuerEntity (
        T01_INV_ID bigint not null,
        T01_ISS_ID bigint not null,
        primary key (T01_INV_ID, T01_ISS_ID)
    )
    
    alter table InvestorIssuerEmailEntity 
        add constraint FKC2FBCC4E1E26612E 
        foreign key (T02_INV_ID, T02_ISS_ID) 
        references InvestorIssuerEntity
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Envers on a project that also uses Hibernate and
I have been trying to use Hibernate for a while. I like hibernate that
I have been trying to use the hibernate dialect for SQLite from http://code.google.com/p/hibernate-sqlite/ in
I have a Spring application which uses Hibernate on a PostgreSQL database. I'm trying
I'm trying to use hibernate to build up a local cache of data that
Im trying to convert the Vaadin demo for JPAContainer to use hibernate instead of
I have a console command line app that use NHibernate . I am trying
I've been trying to use #harp architecture and Fluent-NHibernate. I am trying to sublass
I have been trying to get to grips with Hibernate's inverse attribute, and it
I'm trying to use an existing database with Grails. My DataSource.groovy starts with this:

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.