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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:47:38+00:00 2026-06-04T17:47:38+00:00

I’m trying to map a table (legacy from the Oracle Forms time) that have

  • 0

I’m trying to map a table (legacy from the Oracle Forms time) that have only a Unique Key, because some values can be null. The user can choose if the data in other applications exists in char or number and the table have the two fields (one varchar2 and other number).

It is possible to use a Domain Class for this?

Example

Mytable
---------------------------------------------------------------
office_schedule_id        NUMBER(5) NOT NULL
office_company_char       VARCHAR2(6)
office_schedule_char      VARCHAR2(10)
office_company_num        NUMBER(6)
office_schedule_num       NUMBER(5)
default                   VARCHAR2(1)

The unique constraint is composed by all fields except “default”.

I’ve tried this:

class OfficeSchedule {
   int officeScheduleId
   String officeScheduleName

   static mapping = {
     version false
     table 'office_schedules'
     id column: 'office_schedule_id', name: 'officeScheduleId'
   }

   static hasMany = [ schedules : IntegrationSchedules ]
}
//this represents MyTable
class IntegrationSchedules {
    String officeCompanyChar
    String officeScheduleChar
    Integer officeCompanyNum
    Integer officeScheduleNum
    String default

    static belongsTo = [ officeSchedule : OfficeSchedule ]

    int hashCode() {
      def builder = new HashCodeBuilder()
      //added all fields of the unique key
      builder.toHashCode()
    }

    static mapping = {
      version false
      table 'mytable'
      id composite: ['officeSchedule','officeCompanyChar','officeScheduleChar','officeCompanyNum','officeScheduleNum']
      officeSchedule(column:'office_schedule_id')
    }

}

When I try to query, only five of 56 records returns

println IntegrationSchedules.findAll().size() //prints 5 but table have 56

I tried remove the relation with OfficeSchedule, but still returns just five rows.

I noticed then that the rows that return is because they have all fields informed, that makes sense because I’m defining the key as if it were a PK.

I cannot change the table because are legacy applications that use it.

One workaround that I think is to transfor this as a groovy bean and use a service to create the objects, but with this I cannot use the criteria and GORM findBy methods.

  • 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-04T17:47:40+00:00Added an answer on June 4, 2026 at 5:47 pm

    My solution was, as mentioned by @ideasculptor, to create a hibernate mapping:

    src/java/domain

    @Entity
    @Table(name = "mytable")
    class IntegrationSchedules {
        @Id()
        @Type(type="string")
        @Column(name="rowid")
        private String rowid;
        private String officeCompanyChar
        private String officeScheduleChar
        private Integer officeCompanyNum
        private Integer officeScheduleNum
        private String default
    
        //getters & setters ommited
    }
    

    And I had to create a hibernate config (hibernate.cfg.xml in conf/hibernate)

    <!DOCTYPE hibernate-configuration SYSTEM
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
        <session-factory>
            <mapping package="domain" />
            <mapping class="domain.IntegrationSchedules" />
        </session-factory>
    </hibernate-configuration>
    

    The interesting is that dynamic methods of GORM works, eg:

    IntegrationSchedules.findAll()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.