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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:42:20+00:00 2026-06-01T22:42:20+00:00

I have three domain classes User , Employee and UserEmployee . class User {

  • 0

I have three domain classes User, Employee and UserEmployee.

class User {
    String username
    //more atributes omitted 

    static hasMany = [ userEmployees : UserEmployee ]
    static mapping = {
      version false
      table 'myUserTable'
       id column: 'username', name: 'username' 
    }
}

class Employee {
    long employeeCode
    //more atributes omitted 
    static hasMany = [ userEmployees : UserEmployee ]
    static mapping = {
       id column: 'myColumn', name: 'employeeCode' 
       version false
       table 'myViewHere'
    }
}

class UserEmployee implements Serializable {
    User user
    Employee employee
    static belongsTo = [ user : User,  employee : Employee ]
    static mapping = {
      version false
      table 'myRelationTable'
      id composite: ['user','employee']
      user(column: "username")
      employee(column: "myColumn")
    }
}

When I try to query all the employees that some user can access, I get the ORA-00904 error:

println UserEmployee.withCriteria {
    projections {
       user {
           eq('username', 'SOMEUSER')
       }
    }
}

The hibernate output is something like this:

Hibernate: select * from ( select this_.username as usuario27_0_, from myUserTable this_ where this_.username=? ) where rownum <= ?

Hibernate: select this_.username as usuario24_0_, this_.code_employee as cod2_24_0_ from myRelationalTable this_ where (usu_alias1x1_.username=?)

Why is the alias usu_alias1x1_ created?

P.S.: I changed the domain classes names and fields to better understanding. Maybe will be a typo somewhere.

EDIT

I’m mapping a database that already exists and cannot have the PK’s changed to the Grails default. So I’m using the id column to declare the keys.

  • 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-01T22:42:22+00:00Added an answer on June 1, 2026 at 10:42 pm

    Well, I changed the query to:

    Employee.createCriteria().list() {
      projections {
        userEmployees {
          eq('user', someUser)
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three classes (domain, role and user). Domain and role are properties of
I have two domain-classes. class UsersAddThese { String someData } and class TheseAreConstantlyGenerated {
I have two domain classes: class Domain1 { String val11 String val12 Domain2 domain2
suppose I have a domain classes: public class Country { string name; IList<Region> regions;
Have three classes User, Group and Field. Many to many relationship on User /
I have two domain classes with a many-2-many relationship between them, e.g. User and
I have there domain classes: Person. (Person.ID, Name,Address) Designation.(Designation.ID, Title, Band) SalarySlip (Person.ID, Designation.ID,
I have a website with three domains .com, .de and .it Each domain needs
If I have a List in a Grails domain class, is there a way
Let's say I have a UserAccount domain class that has a UserPreferences domain class.

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.