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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:25:50+00:00 2026-06-08T12:25:50+00:00

Im stuck with this problem. The database schema is provided by someone else so

  • 0

Im stuck with this problem. The database schema is provided by someone else so I cant simply change names. I tried add everywhere proper annotations, maybe I’m missing something (obvious)?

Here is my full mapping (quite many classess), I’ll ommit getter/setters.

The problem is when hibernate is trying to get all List<ControlRuleAttrib> controlRuleAttribs

Controle Rule

@Entity
@Table(name = "CONTROL_RULE")
public class ControlRule implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Column(name = "CONTROL_RULE_ID")
 private Long id;
 @ManyToOne(fetch = FetchType.LAZY)
 @Cascade(CascadeType.ALL)
 @JoinColumn(name = "CONTROL_RULE_TYPE_ID")
 @ForeignKey(name = "CONTROL_RULE_TYPE_ID")
 private ControlRuleType controlRuleType;
 @Column(name = "JOB_NM")
 private String jobname;
 @Column(name = "LIBRARY_NM")
 private String libraryname;
 @Column(name = "TABLE_NM")
 private String tablename;
 @Column(name = "COLUMN_NM")
 private String columnname;

 @OneToMany(fetch = FetchType.LAZY)
 @Cascade(CascadeType.ALL)
 @JoinTable(name = "CONTROL_RULE_ATTRIB", joinColumns = {
  @JoinColumn(name = "CONTROL_RULE_ID", nullable = false, updatable = false)
 })
 private List < ControlRuleAttrib > controlRuleAttribs;
}

ControlRuleAttrib

@Table(name = "CONTROL_RULE_ATTRIB")
@Entity
public class ControlRuleAttrib {
 @EmbeddedId
 private ControlRuleAttribPK controlRuleAttribPK;

 @Column(name = "ATTRIBUTE_VALUE")
 private String attributeValue;
}

ControleRuleAttribPK
Question here is, is it possible to somehow get Entity ControlRuleAttribType from ControlRuleAttrib? As you can see below ControlRuleAttribTypeId is the id of ControleRuleAttribType. I’d like to get whole object isteand of integer.

@Embeddable
public class ControlRuleAttribPK implements Serializable {
 @Column(name = "CONTROL_RULE_ID")
 private Long controlRuleId;

 @Column(name = "ATTRIBUTE_SEQ_NUM")
 private Integer attributeSeqNum;

 @Column(name = "CONTROL_RULE_ATTRIB_TYPE_ID")
 private Integer controlRuleAttribTypeId;
}

ControleRuleAttribType

@Entity
@Table(name = "CONTROL_RULE_ATTRIB_TYPE")
public class ControlRuleAttribType implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Column(name = "CONTROL_RULE_ATTRIB_TYPE_ID")
 private Integer id;
 @Column(name = "CONTROL_RULE_ATTRIB_TYPE_NM")
 private String typename;
 @Column(name = "CONTROL_RULE_ATTRIB_TYPE_DESC")
 private String typedesc;

 @ManyToOne(fetch = FetchType.LAZY)
 @Cascade(CascadeType.ALL)
 @JoinColumn(name = "CONTROL_RULE_TYPE_ID")
 @ForeignKey(name = "CONTROL_RULE_TYPE_ID")
 private ControlRuleType controlruletype;
}

ControleRuleType

@Entity
@Table(name = "CONTROL_RULE_TYPE")
public class ControlRuleType implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Column(name = "CONTROL_RULE_TYPE_ID")
 private Integer id;
 @Column(name = "CONTROL_RULE_TYPE_NM")
 private String typename;
 @Column(name = "CONTROL_RULE_TYPE_DESC")
 private String typedesc;
}

EDIT

Here is stacktrace:

https://gist.github.com/a30dd9ce534d96bb9a97

As you’ll find out, it fails here:

at
com.execon.controllers.main.MainPageController.getMainPage(MainPageController.java:33)
[classes:]

and this is it:

List<ControlRule> list = SessionFactoryUtils.openSession(
    sessionFactory ).createQuery( "from ControlRule" ).list();
System.out.println( list );

every object which mapping I added, has toString() method declared like this:

@Override
public String toString()
{
    String s = "ControlRule{";
    s += "id=" + id.toString();
    s += ", controlRuleType=" + controlRuleType;
    s += ", jobname='" + jobname + '\'';
    s += ", libraryname='" + libraryname + '\'';
    s += ", tablename='" + tablename + '\'';
    s += ", columnname='" + columnname + '\'';
    s += ", controlRuleAttribs=" + controlRuleAttribs;
    s += '}';
    return s;
}

And hibernate request:

https://gist.github.com/c8584113522757a4e0d8/4f31dc03e7e842eef693fa7ba928e19d27b3ca26

Help please 🙂

EDIT 2

Well after reading @Jens answer, I did some changes in the code. First I did as you wrote and it gave error:

org.hibernate.AnnotationException: A Foreign key refering
com.execon.models.controlrules.ControlRuleAttrib from
com.execon.models.controlrules.ControlRule has the wrong number of
column. should be 3

I guess this is right, as I have composite primary key.

Then I tried it this way:

@OneToMany(fetch = FetchType.LAZY)
@Cascade(CascadeType.ALL)
@JoinTable(name = "CONTROL_RULE_ATTRIB",
        joinColumns = {
                @JoinColumn(name = "CONTROL_RULE_ID", nullable = false, updatable = false)
        },
        inverseJoinColumns = {
                @JoinColumn(name = "CONTROL_RULE_ID", nullable = false, updatable = false),
                @JoinColumn(name = "CONTROL_RULE_ATTRIB_TYPE_ID", nullable = false, updatable = false),
                @JoinColumn(name = "ATTRIBUTE_SEQ_NUM", nullable = false, updatable = false)
        })
private List<ControlRuleAttrib> controlRuleAttribs;

Quite close but it gives me the following exception:

Repeated column in mapping for collection..

So finally I removed

joinColumns = 
{
    @JoinColumn(name = "CONTROL_RULE_ID", nullable = false, updatable = false)
}

And everything compiled except that when I try to reach collection, Hibernate is doing following query:

https://gist.github.com/c88684392f0b7a62bea5

The last line, is controlrul0_.CONTROL_RULE_CONTROL_RULE_ID=? while it should be controlrul0_.CONTROL_RULE_ID=?.

Is there anyway I can make it work? :/

  • 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-08T12:25:51+00:00Added an answer on June 8, 2026 at 12:25 pm

    After struggling with this for last few hours I finally make it working within my project. The thing I did was this:

    ControlRule

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "controlRuleAttribPK.controlRuleId")
    @Cascade(CascadeType.ALL)
    private List<ControlRuleAttrib> controlRuleAttribs;
    

    Basically pointing that the collection should use controlRuleId from composite primary key. So far its working great!

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

Sidebar

Related Questions

For a few days Im being stuck at this problem, I've tried to delete/clean
I'm hoping someone can help me as I've been stuck on this problem for
I have been stuck on this problem for quite awhile... I hope someone out
Hello everyone I am completely stuck with this problem. I want add the name
Hi i got stuck with this problem, i can't find out how to get
So I'm stuck on this problem where I've been asked to write an function
I am currently stuck at this problem right now where I don't seem to
I got stuck in this problem for an hour. I am thinking this is
I'm currently stuck on this problem. I've hooked into the method_missing function in a
I got stuck with this problem. I wrap two tables inside of a h:form.

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.