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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:30:27+00:00 2026-06-04T12:30:27+00:00

I am lost on how to use composite keys with annotations and hibernate… So

  • 0

I am lost on how to use composite keys with annotations and hibernate…

So for instance I have this table that has:

TABLE_A

INIT,
NUM,
CNT,
TYP

TABLE_B

INIT,
NUM,
V_CNT

TABLE A and B primary keys are composite keys consisting of INIT and NUM

I want to run my query:

   "FROM TABLE_A AS A " +
   "LEFT JOIN A.hiber_join AS B " +
   "WHERE A.INIT||A.NUM IN (:carList) AND A.INIT IN (:initList) AND A.NUM IN              (:numberList) " + 
    "AND B.V_CNT > 0

My Classes look like:

*Class_A*

public class TABLE_A implements Serializable{

private String INIT;
private String NUM;
private Integer CNT;
private String TYP;

    @OneToOne
@JoinTable(name = "TABLE_B",
    joinColumns = {@JoinColumn(name = "INIT"), @JoinColumn(name = "NUM")}

)
protected TABLE_B hiber_join;

    public TABLE_A()
    {}

    public void doHibernateStuff()
    {
     //call query get result set
    }

}

//Class B

public class TABLE_B implements Serializable{

private String NUM;
private String INIT;
private Integer V_CNT;
}

I tried to make it as simple as possible because I need to from the very basics of how to use hibernate and the annotations…as you can tell I have a been working a while and hibernate documentation and other questions has not seemed to help…

  • 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-04T12:30:28+00:00Added an answer on June 4, 2026 at 12:30 pm

    AFAIK, you need to use PrimaryKeyJoinColumn (I changed the class and attribute names to conform to standard Java naming conventions, but you should choose meaningful names):

    public class BEntity implements Serializable{
    
        @Id
        @Column(name = "NUM")
        private String num;
    
        @Id
        @Column(name = "INIT")
        private String init;
    
        @Column(name = "V_CNT")
        private Integer vcnt;
    }
    
    public class AEntity implements Serializable{
    
        @Id
        @Column(name = "NUM")
        private String num;
    
        @Id
        @Column(name = "INIT")
        private String init;
    
        @OneToOne
        @PrimaryKeyJoinColumns({
            @PrimaryKeyJoinColumn(name="NUM", referencedColumnName="NUM"),
            @PrimaryKeyJoinColumn(name="INIT", referencedColumnName="INIT")
        })
        private BEntity bEntity;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this PHP code that I use to make a dropdown form selection
I've lost the toolbar on my DataFormWebPart that has the dropdown boxes that apply
I'm a bit lost with the use of Inject on variable. I got this
I have this fiddle which has an error --> http://jsfiddle.net/Osoascam/AkZZr/6/ (This is the version
I want to use FileSystemObject, but it lost in DCOMCNFG, I have register it
Im getting really lost on how to use HttpContext.User. I read everywhere that its
I am so lost on this. I am trying to use the publishUserAction feature
When I use this valgrind --leak-check=yes ./Main I have about 185236 errors. It said
When I use this valgrind --leak-check=yes ./Main I have about 185236 errors. It said
I lost a week of time on this. I wanted to use a LinkButton

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.