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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:28:17+00:00 2026-06-01T01:28:17+00:00

I have four class; UserGroup, UserAccount, Role, UserGroupRoleRelation and my db is IBM DB2

  • 0

I have four class; UserGroup, UserAccount, Role, UserGroupRoleRelation and my db is IBM DB2

@Entity
@Table(name = "USER_GROUP")
public class UserGroup implements Serializable {

    @Id
    @Column(name = "USER_GROUP_ID")
    @GeneratedValue
    private Long id;
......
..
    @OneToMany(mappedBy = "userGroup", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<UserGroupRoleRelation> userAccountsRole = new ArrayList<UserGroupRoleRelation>();


}




@Entity
@Table(name = "ROLE")
public class Role implements Serializable {

    @Id
    @Column(name = "ROLE_ID")
    @GeneratedValue
    private Long id;

    ......

    @OneToMany(mappedBy = "role")
    private List<UserGroupRoleRelation> userAccountInGroup = new ArrayList<UserGroupRoleRelation>();


}


@Entity
@Table(name = "USER_GROUP_ROLE_LINE", uniqueConstraints = @UniqueConstraint(columnNames = { "ROLE_ID", "USER_GROUP_ID" }))
public class UserGroupRoleRelation {

    @Id
    @GeneratedValue
    @Column(name = "RELATION_ID")
    private Long relationId;

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "USER_ACCOUNT_USER_GROUP_ROLE_LINE", joinColumns = { @JoinColumn(name = "RELATION_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") }, uniqueConstraints = @UniqueConstraint(columnNames = { "USER_ID", "RELATION_ID" }))
    private List<UserAccount> userAccountList = new ArrayList<UserAccount>();

    @ManyToOne
    @JoinColumn(name = "USER_GROUP_ID")
    private UserGroup userGroup;

    @ManyToOne
    @JoinColumn(name = "ROLE_ID")
    private Role role;
}


@Entity
@Table(name = "USER_ACCOUNT")
public class UserAccount implements Serializable {

    @Id
    @Column(name = "USER_ID")
    @GeneratedValue
    private Long id;
.....

    @ManyToMany(mappedBy = "userAccountList", cascade = CascadeType.ALL)
    private List<UserGroupRoleRelation> rolesInGroup = new ArrayList<UserGroupRoleRelation>();
}

I wanna find usergroups of a useraccount and i prepared a method with criteria. its like;

    @Override
    @Transactional
    public List<UserGroup> findUserGroupOf(UserAccount userAccount) {
        Criteria criteria = getSession().createCriteria(UserGroup.class);
        criteria.createAlias("userAccountsRole", "userAccountsRole");
        criteria.add(Restrictions.eq("userAccountsRole.userAccountList", userAccount));
        return criteria.list();

    }

But when i try to get result of that method, DB2 gives to me DB2 SQL Error: SQLCODE=-313, SQLSTATE=07004, SQLERRMC=null, DRIVER=3.63.75

Probably its about creating alias on many to many relation. I dont know what should i do to create alias on many to many. How can I get result of that function?

Thank

  • 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-01T01:28:19+00:00Added an answer on June 1, 2026 at 1:28 am
        @Override
        @Transactional
        public List<UserGroup> findUserGroupOf(UserAccount userAccount) {
            Criteria criteria = getSession().createCriteria(UserGroup.class);
            criteria.createAlias("userAccountsRole", "userAccountsRole");
            criteria.createAlias("userAccountsRole.userAccountList", "userAccountList");
            criteria.add(Restrictions.eq("userAccountList.id", userAccount.getId()));
            return criteria.list();
    
        }
    

    It works for me. I mean criteria on “id”. But I don’t understand why I cant check equality on object instead of id when there is ManyToMany list

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

Sidebar

Related Questions

I used JPA and mysql. Each table have entity class.I have four tables. Table1
I've got problem in my code in Java. I have four(important) Classes: public class
I have four classes: class A {}; class B : virtual public A {};
I have four div with class name .s-list . When the user clicks on
I have one parent class, which is abstract class for now, for four different
I have a solution which contains six projects. Four of the projects are class
I'm having a problem with assembly references. I have four assemblies: A class library
I have four classes, let's call S1, S2, S3 and S4. These class are
If i have a @OneToMany relationship with @Cascade(CascadeType.SAVE_UPDATE) as follows public class One {
I have four classes. Class Person , and three more, Student , Professor ,

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.