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.contri
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.