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

  • Home
  • SEARCH
  • 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 6135397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:28:27+00:00 2026-05-23T17:28:27+00:00

I have a legacy database which can’t be changed because it’s hooked up to

  • 0

I have a legacy database which can’t be changed because it’s hooked up to a 3rd party application.

One of the queries I’m working with for a new application looks like the following:

SELECT COL1, COL2, COL3, CODE1, CODE2,
(SELECT CODE_DESC FROM CODETABLE WHERE CODE_TYPE='A' CODE=INCIDENT.CODE1) AS CODE_DESC1,
(SELECT CODE_DESC FROM CODETABLE WHERE CODE_TYPE='B' CODE=INCIDENT.CODE2) AS CODE_DESC2
FROM INCIDENT
WHERE...

I’m trying to figure out how to translate that query into a set of Hibernate entities, but I’m a Hibernate newbie. I have 3 questions:

  1. How do I join an entity to another entity in a one-to-one relationship multiple times? (the sub-queries)
  2. How do I join an entity to another entity in a one-to-one relationship using a, for lack of a better word, parameter that has a fixed value (CODE_TYPE=’A’)?
  3. Is it possible to do either of the above using annotations (because I like those)?

Here’s what I’ve tried thus far that didn’t work:

Object 1:

@Entity
@Table (name="Incident")
public class Incident {
    private String col1;
    private String col2;
    private String col3;
    private String code1;
    private String code2;
    private Code code_desc1;
    //private String code_desc2;
    /**
     * @param code_desc1 the code_desc1 to set
     */
    public void setCode_desc1(Code code_desc1) {
        this.code_desc1 = code_desc1;
    }
    /**
     * @return the code_desc1
     */
    @OneToOne
    @JoinTable(name="Codes",
            joinColumns=@JoinColumn(name="code1", referencedColumnName="CODE"),
            inverseJoinColumns=@JoinColumn(name="CODE_TYPE", referencedColumnName="'A'")
    )
    public Code getCode_desc1() {
        return code_desc1;
    }
// Rest of Getters & Setters...
}

Object 2:

@Entity
@Table (name="CODETABLE")
public class Codes {
    @Column(name="CODE_DESC") 
    private String codeDesc;
    @Column(name="CODE_TYPE")
    private String codeType;
    @Column(name="CODE")
    private String code;
// Getters & Setters
}

Basically, when I run the program, it complains about “A” not being a column name in the Codes entity.
Thanks for helping!

  • 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-23T17:28:28+00:00Added an answer on May 23, 2026 at 5:28 pm

    You should create a view as the query you described and define an entity mapping to this view.

    If you still need the “Code” entity mapped at “Incident”, check following example:

    @Entity
    @Table(name="incident")
    public class Incident {
        @Id
        @Column(name="id")
        private Integer id;
    
        @OneToOne
        @JoinColumn(name="code1")
        private CodeA typeACode;
        @OneToOne
        @JoinColumn(name="code2")
        private CodeB typeBCode;
    
        public Incident() {}
    
        public CodeA getTypeACode() { return this.typeACode; }
        public CodeB getTypeBCode() { return this.typeBCode; }
    }
    

    The “CodeA” is an entity mapping to a view, which comply with CODE_TYPE=’A’.
    The “CodeB” is same as above recipe.

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

Sidebar

Related Questions

I am writing an application which works with a legacy database (brownfield). I have
I have this legacy database for which I'm building a custom viewer using Linq
I have to connect to a legacy postgres database which has ENCODING = 'SQL_ASCII';
I have a table which has essentially boolean values in a legacy database. The
I have a legacy VB6 application that uploads file attachments to a database BLOB
I currently have a database that gets updated from a legacy application. I'd like
I have two data sources: a legacy one (web service) and a database one.
Because of legacy data which is not available in the database but some external
I have legacy database in which transaction tables are stored by monthly names. eg.
I have a legacy database which contains simple data structures (no CODE refs thank

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.