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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:03:50+00:00 2026-05-18T00:03:50+00:00

I am wondering if is possible to implement following domain model. Let’s have a

  • 0

I am wondering if is possible to implement following domain model.

Let’s have a domain class which contains set of intervals (joda time). I can use org.joda.time.contrib.hibernate.PersistentInterval hibernate user type for mapping of Interval to database table (by similar way as in http://www.grails.org/JodaTime+Plugin). However I cannot figure out how to implement mapping if I have set of intervals, not only one interval.

Example:

class Activity {  
   ...    
   Set intervals = []  
   ...  
   static hasMany = [    
       intervals: org.joda.time.Interval  
   ]  

   // This is incorrect implementation, I have set of intervals  
   // and this would be correct if I had only one interval  
   // How to implement mapping in this case?  
   static mapping = {  
       intervals type: PersistentInterval, {  
           column name: "start"  
           column name: "end"  
       }  
   }  

}

Implementation above fails with following error:

2010-10-23 18:30:25,483 [main] ERROR
context.GrailsContextLoader – Error
executing bootstraps: Error creating
bean with name ‘messageSource’:
Initialization of bean failed; nested
exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
‘transactionManager’: Cannot resolve
reference to bean ‘sessionFactory’
while setting bean property
‘sessionFactory’; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
‘sessionFactory’: Invocation of init
method failed; nested exception is
org.hibernate.MappingException:
Foreign key
(FK4FDC5B1E5107CA0:activity_intervals
[start,end])) must have same number of
columns as the referenced primary key
(activity [id])
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
‘messageSource’: Initialization of
bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
‘transactionManager’: Cannot resolve
reference to bean ‘sessionFactory’
while setting bean property
‘sessionFactory’; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
‘sessionFactory’: Invocation of init
method failed; nested exception is
org.hibernate.MappingException:
Foreign key
(FK4FDC5B1E5107CA0:activity_intervals
[start,end])) must have same number of
columns as the referenced primary key
(activity [id])
at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)

I thought that work-around of this issue is to extract Interval to separate domain class extending Interval and specify mapping within it. However, Interval is final class so extending is not possible.

Thanks for your advices.

  • 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-18T00:03:51+00:00Added an answer on May 18, 2026 at 12:03 am

    I am replying my own question, maybe this answer will be useful for someone.

    Until now I have found only one way how to implement given model – by Hibernate XML mapping files:

    <hibernate-mapping package="mappingtest">  
        <class name="Activity">  
            <id name="id">  
                <generator class="native"/>  
            </id>  
            <set name="intervals">  
                <key column="activity_id" not-null="true"/>  
                <element type="org.joda.time.contrib.hibernate.PersistentInterval">  
                    <column name="startDate"/>  
                    <column name="endDate"/>  
                </element>  
            </set>  
        </class>  
    </hibernate-mapping>  
    

    and domain class implementation:

    class Activity {    
        Long id    
        Set intervals = []
    
        static constraints = {
        }
    }
    

    I also had to move domain class from grails-app/domain to src/groovy directory, otherwise application running failed with (grails-1.3.5):

    …
    org.hibernate.DuplicateMappingException:
    Duplicate class/entity mapping
    mappingtest.Activity
    …

    Second problem with above implementation I have discovered is that when I turned on scaffolding (for testing purpose) by:

    class ActivityController {
        static scaffold = true
        ...
    }
    

    showing of created activity failed with error:

    Exception Message: No such property:
    id for class: org.joda.time.Interval
    Possible solutions: end Caused by:
    Error evaluating expression [i.id] on
    line [38]: No such property: id for
    class: org.joda.time.Interval Possible
    solutions: end

    but manual implementation of getting activities from DB and its showing worked.

    Edit: additionally I found solution of scaffolding and DuplicateMappingException issues. They were caused by invalid location of Activity.hbm.xml – package directory structure was missing. Correct location is grails-app/conf/hibernate/mappingtest/Activity.hbm.xml.

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

Sidebar

Related Questions

I'm wondering how you'd implement the following use-case in REST. Is it even possible
I'm wondering if its possible to add new class data members at run-time in
I was wondering if its possible to inject a thread into a remote app
I am wondering if it is possible to extract the index position in a
I was wondering if it is possible to not attach Excel sheet if it
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific
I was wondering if it would be possible to retrieve the complete list of
I was wondering if it is possible to generate a core file, copy if
I was wondering if it is possible to do something like this: <uc1:TestControl ID=TestControl1
I'm wondering if it is possible to add methods in main program to an

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.