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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:01:13+00:00 2026-05-17T01:01:13+00:00

I have a few domain classes, and I want to be able to populate

  • 0

I have a few domain classes, and I want to be able to populate a new Domain class and persist it to the database via one of my controllers. Here are my classes

class Employee implements Comparable
{
    static hasMany = [education:Education]
    static mapping = {
        education cascade:"all,delete-orphan", lazy:false
    }
    List<Education> education = new ArrayList<Education>();
}


public class Education implements Comparable
{
   static belongsTo = [employee:Employee]
   String collegeName
   String areaOfStudy
   String yearGranted
   Date lastModified
   Boolean inProcess = false;
   EducationType type = new EducationType(name:"None");
}


class EducationType
{
    String name="";
}

Now I want to create a new Education entry for a particular employee from this controller.

        def employee = Employee.get(session.empid);
        EducationType et = new EducationType(name:'JD')
        Education ed1 = new Education(collegeName:'Harvard1', areaOfStudy:'Law', yearGranted:'2015', type:et, lastModified:new Date(), employee:employee)

        employee.addToEducation(ed1)
        employee.save()

For some reason this is not behaving as expected and I get this exception:

2010-09-24 10:56:01,503 [http-8080-1] ERROR errors.GrailsExceptionResolver  - not-null property references a null or transient value: Education.type; nested exc
eption is org.hibernate.PropertyValueException: not-null property references a null or transient value: Education.type
org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: Education.type; nested exception is org.hiberna
te.PropertyValueException: not-null property references a null or transient value: Education.type
        at org.jsecurity.web.servlet.JSecurityFilter.doFilterInternal(JSecurityFilter.java:382)
        at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)
        at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: Education.type
        ... 3 more

I can get this to go away by first saving the EducationType with an et.save() and then saving the Education object with ed.save() and finally saving the employee.

Why is this necessary? Doesnt my mapping say that a save on employee should trickle down to any non-persisted objects that are now associated with the employee?

Also – why do I have to explicitly add employee when I initalize the Education object? It is specified in the belongsTo object, and it seems like when I do the employee.addToEducation() call it should be picked up automatically, right?

Thanks!

  • 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-17T01:01:13+00:00Added an answer on May 17, 2026 at 1:01 am

    Your Education to EducationType is defined as a simple one-to-one. To cascade from Education to EducationType, I think you can make the latter belongTo the former. Check out 5.2.1.1 of the user guide. Note you have to be careful of what persistence semantics you want? Do you really want EducationTypes to be their own entities?

    I think you have to add the employee to Education because you have a bidirectional one to many. Both sides of the relationship have to be set up. addToEducation works to add to the owning side of the relationship a member of the collection. Evidently, It does not set the relationship from the owned side to the owning side.

    —- edit —-

    I just looked at the docs because your second error seems wierd

    “The addTo* method is a dynamic method that uses an association to automatically add instances to the association. It also automatically configures bi-directional relationship so that both sides o the relationship have been set.”

    So it seems that addTo should be setting both sides of the relationship…If you take the employee: employee out of your Education creation it does not work?

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

Sidebar

Related Questions

I have a few domain aliases, while I only want one of them to
I have 50 emails for one domain but out of them only few are
I'm trying to redirect a few pages to a new domain and I have
I have some methods that are common across a few of my domain classes.
I have a few subdomains to my domains and I want the domain to
I have two domain classes: Contract and Orgainisation . A contract has one contractor
I have few graphic effects on image which i am able to run on
I have a few HTML files that I'd like to include via tags in
I have the following domain object: public class DomainObject<T,TRepo> where T : DomainObject<T> where
I have a few design-related questions: should service layer interfaces reside in a domain

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.