Questions tagged [gorm]

0

votes
0

answer
2

Views

GORM Zero-to-Many: Cannot add or update a child row: a foreign key constraint fails

I am new to Golang and Gorm. I want to parse API response and store two tables. For each "reports" table, there can be zero-to-many tables of "personal_details". However, gorm gave error when applying foreign key constraint because there's no record for PersonalDetail in API response sometimes. I...
Giwi
1

votes
1

answer
496

Views

Grails save() tries to create new object when it should update

In my service code, I am trying to create or update a Person domain object: @Transactional def someServiceMethod(some params....) { try{ def person = Person.findByEmail(nperson.email.toLowerCase()) if (!person) { person = new Person() person.properties = nperson.properties } else { // update the per...
rahulserver
1

votes
2

answer
79

Views

Grails generate-all generates a Service class ( 3.2.3 )

Since new Grails version 3.2.3 the command generate-all generates a service grails.gorm.services.Service named Service which is an interface What is the actual implementation of this, which I can edit?
user39950
1

votes
1

answer
306

Views

How do I know if Grails domain POJO was changed since its retrieval?

I am patching a domain object in my code. At the end, I need to save the object but only if it has been actually changed. Is it possible to avoid custom boolean flags having code like that? User user = User.find(...) if(maybe) user.name = "John" if(user.changed()) user.save()
Pavel Vlasov
1

votes
1

answer
727

Views

Grails transient property not validating error?

I have a domain class: class Book { String id Date dateCreated Date lastUpdated String title boolean acceptPolicy // defines if the user accepts the terms and privacy poicy String uploadImageId static transients = [ "acceptPolicy" ] static constraints = { acceptPolicy( validator: { val, obj -> v...
confile
1

votes
2

answer
427

Views

How to convert between GRAILS' class column and hibernate's DTYPE column in GORM

I have the following problem. I got a database schema generated by JPA/Hibernate in Java. I have one table for an inheritance hierarchy. For this to work Hibernate uses a DTYPE column to distinguish between the concrete implementations of the classes in my hierarchy. I now need to load that same hie...
ali
1

votes
2

answer
809

Views

using findAndModify in mongodb using grails gorm

I need to use findAndModify in my application with grails and mongoDB. I used this code : public static String getNextId(DB db, String seq_name) { String sequence_collection = "seq"; // the name of the sequence collection String sequence_field = "seq"; // the name of the field which holds the sequen...
zorro6064
1

votes
3

answer
669

Views

Grails -Custom Sorting with associated domain class

I have domain Training class Training { static belongsTo = [venue: Venue] } Venue class Venue { static belongsTo = [city: City] } City class City { String name } now i want to sort Training based on City name . is there a way to do it in Grails (Gorm)way?
maaz
1

votes
1

answer
639

Views

Grails - owning side of relationship not persisted when using a List

I am experiencing a strange problem when trying to persist an association between two entities. When I use a Set (i.e. the Grails default), it works, however if I try to use a List, the association in the child table is lost somewhere between setting it in my domain class and the SQL insert statemen...
rcgeorge23
1

votes
1

answer
2.3k

Views

grails beforeDelete with many-to many relation

I have 2 domain class with a many to many relationship. When I delete the entity that belongs to the other, I have to remove the relation before in order to avoid a foreign key error. I would like to put this code in the beforeDelete event, but I obtain a problem with optimistc locking. This is the...
1

votes
1

answer
572

Views

Grails composite id throwing NullPointerException

I have a Grails 2.2.3 domain class that is throwing a NullPointerExeption regarding my composite id when I use dynamic scaffolding. I would just use the pidm field as the primary key, but occasionally there are two records with the same pidm (same employee, but maybe there is a name change or someth...
1

votes
3

answer
215

Views

Grails querying the database against a list of objects

I'm creating an application with Grails. I have two domain classes: parent and child: class Parent { string name hasMany[children: child] } class Child { string name belongsTo[parent: parent] } I search for all the parents with a name similar to a keyword: def parents = Parent.findAll("From Parent a...
Jacopo
1

votes
1

answer
713

Views

Handling a hasMany relationship in a object marshaller

I'm in the process of writing a custom JSON object marshaller in Grails 2.2.4. The class that I'm trying to convert to JSON has both a belongsTo and a hasMany relationship. I can access the belongTo information presumably because the relationship is 1-* but I can't access the hasMany information in...
Sam Marland
1

votes
1

answer
728

Views

GORM, Envers and @NotAudited relationships or adding annotations to hasMany-relation

I am using hibernate envers with Grails, defining some entities with @Audited to let them audited by the API. Some entities should not be audited, so I am defining @Audited(... NOT_AUDITED) which runs also smoothly. But this time, I have a relationship defined following static hasMany = { foos : Foo...
Michael Wölm
1

votes
1

answer
160

Views

Better approach to solving filters than if/else

In my list method I will be passing several filters from the client side. Currently I have a long list of if/else blocks that get executed based on the params coming in. I'm wondering if there is a better way to approach this? def list () { println params def list = [] if (params["Column1"] != nul...
Anthony
1

votes
2

answer
232

Views

How to write this Grails GORM Hibernate query

New to GORM, can't figure how to do this query. Here are my domain classes (minus unnecessary info): User {...} //domain object (from springsecurity) BasicProfile { User user static hasMany = [applicants:Applicant] } Applicant { static belongsTo = BasicProfile int applicantNumber } My BasicProfile...
spock99
1

votes
1

answer
635

Views

MongoDB Grails GORM unexpected behavior with hasMany / belongsTo

Context: I'm using the mongodb plugin, although this may have nothing to do with that. Let's say I have two domain classes, Foo and Bar, where Foo hasMany Bar and Bar belongsTo Foo: class Foo { static hasMany = [bar:Bar] } class Bar { static belongsTo = [foo:Foo] } I would expect that what would be...
The McG
1

votes
3

answer
837

Views

Grails GORM + Mongo, How to save custom data to id?

Try to save something custom in id field in Grails: Cover saveCover = new Cover(id: url, url: url, name: name, sku: sku, price: price) But in DB I see that in _id field something like this: 52658d9284aea229e226ab9c. It confuse me, cause it looks like ObjectId, but not string that I send to Cover dom...
sphinks
1

votes
2

answer
450

Views

constructing Grails/Groovy where query in run-time

Is it possible to construct such query in run-time in grails/groovy ? Let's say I have: def query = Person.where { age in 18..65 } and in run-time I wanna add weight to it as : def query = Person.where { age in 18..65 weight in 100..200 } possible ?
AlexCon
1

votes
3

answer
313

Views

Grails + RESTful URL mapping + Filters + Routes

Member have many jobs. A member can add, delete or update Jobs. Currently there are actions (add, delete or update) defined in a controller which are called through jQuery.ajax(). We are sending job id and member id to perform the operation. Member id is necessary because there is a role admin who c...
Umair Saleem
1

votes
1

answer
285

Views

Retrieving children from a particular parent for display on a select component

I have a parent-child domain-class relation in Grails as shown, and I want to retrieve all the children of one specific parent object in order to display them in a HTML select component for the user to pick. class Parent { static hasMany = [children: child] } class child { string name Parent pare...
JLA
1

votes
2

answer
974

Views

Grails + mysql Create table name and column name in Upper case

Creating mysql table from Grails domain class does not generates table and column name in Uppercase letters. table names are created in lowercase . Even when doing reverse-engineer with table names in uppercase letters the domain class is generated in lowercase only. How to created table with table...
Muthu
1

votes
2

answer
144

Views

Grails MongoDb findBy

I'm sure it must be a simple solution but I cannot find it. I have a grails project with a MongoDb database. I want to do a find operation. Using mongo shell I have: > db.event.find({'author.id':'22'}) But I cannot the same thing inside my grails project. I have tried something like: Event.find(['a...
CC.
1

votes
2

answer
725

Views

Grails save without changing attributes doesn't trigger beforeUpdate

I have a problem, I have a domain class called Cicle that calculates the value of some of its properties by making an average from a collection of other domain class called Measurement, so if any of its Measurements is updated then the Cicle should be updated too. The problem is that I calculate the...
Ana Franco
1

votes
1

answer
65

Views

Why do we need explicit relationships in grails?

I am a beginner in GRAILS so i am hoping some help on the issue i am facing. I have read the documentation but i am still vague on the idea of relationships in grails. In grails, you could have 4 types of relationship between domain classes. 1 to 1 1 to many many to 1 many to many Grails has three...
user3256520
1

votes
2

answer
735

Views

Grails: Apply a custom constraint to all fields of an Domain class

In Grails it's possible to define global constraints within the Config.groovy file which can be used to validate all defined constraints from every domain class using Config.groovy: grails.gorm.default.constraints = { '*'(nullable: true) ... } Question: Is it also possible to define a constraint whi...
seb
1

votes
2

answer
1.8k

Views

hasMany save not working on Grails 2.4.2 upgrade

I recently upgraded from Grails 2.2.5 to 2.4.2 . After the upgrade a lot of my hasMany relationships are not saving. For Example: Domains: class Node { String name String description static belongsTo = CustomGlobe static hasMany = [containers: Container] } class Container { String name CustomGlobe...
Brandon Wagner
1

votes
1

answer
380

Views

Grails Domain Class Transactions

It's obviously best to put transactional code in Grails services for a lot of different reasons. However, are Domain classes transactional like services are? It seems to make intuitive sense to put my data-binding for domain specific fields in the domain class and even use some Groovy conventions t...
Brandon Wagner
1

votes
1

answer
146

Views

Grails criteria query checking `OR` logic

I having grails criteriaQuery where I am checking OR logic againist a single state variable like this: or { eq("status", Status.ONE) eq("status", Status.TWO) eq("status", Status.THREE) } This code is working fine, My question is, as I am checking OR logic againist a single state, Is there any way to...
1

votes
1

answer
289

Views

GORM not bootstrapping from JAR

Replacing a persistence layer in legacy app with a JAR file using Spring, Hibernate and GORM. Methods like person.save() work fine when running agains project with Gradle etc. in project. However, after I build the fat jar and reference it with -cp my-big-fat-gorm.jar I get: java.lang.IllegalState...
Todd W Crone
1

votes
1

answer
1.8k

Views

Cloning an instance of domain in Grails

I'm wondering how I would go about adding the functionality of cloning to my grails application. I've attached an image below that explains how my domain classes are associated. One template has many steps and those steps each have many inputs and or outputs. Currently I can view my templates on the...
Jamie
1

votes
2

answer
902

Views

GORM read only columns

Most of our tables have one or more columns which are set by the database, either by a trigger, or we want to use the database default value (which requires not sending the field at all in the insert or update) This includes transaction dates set in the dB (so all the times are times stamped very ac...
John Little
1

votes
1

answer
98

Views

findAll order by “many to one” column raises exception

I have an entity, Student, defined in Student.groovy as: @EqualsAndHashCode(includes = ['id']) class Student { Long id String name String type University university static mapping = { university column : 'UNIVERSITY_ID' } } and a University entity, defined in University.groovy as: class Univer...
Tudor Vintilescu
1

votes
1

answer
939

Views

Grails Error Code

I am trying to determine what the Error Code is from an exception that is thrown when interacting with a domain object in Grails. I have a database that has some field validations, and one of the validations is that a specific column must be unique. According to the docs it will give an Error Cod...
Alex Sneed Miller
1

votes
1

answer
637

Views

Grails: text instead of varchar

I need the MySQL column type for the String field in my Domain class to be TEXT or VARCHAR(3000), but nothing I try seems to work - it remains VARCHAR(255). I've tried static mapping = { longString type: 'text' } and static mapping = { longString sqlType: 'text' } and static constraints = { longS...
weide
1

votes
1

answer
926

Views

Groovy List of domain object not saved and not sorted in controller

I have a groovy domain class. Fields are not mapped to database. Controller creates a list of such object and sort it before send to the view. instances = instances.sort() { it.part_number } It didn't sort. And print members of the list returns 0 for integer field, null for String field. Printing t...
johnsam
1

votes
2

answer
690

Views

Is it possible to save a specific id for a grails domain object?

I am in the process of trying to copy the properties of one domain object to another similar domain object (Basically moving retired data from an archive collection to an active one). However, when I try to save with a manually inputed id the save will not actually put anything into the collection....
David B
1

votes
1

answer
374

Views

Grails, GORM, update method persists object before calling save()

I have a domain Class DailyBooking and a generated Controller. In the update function I'm calling userService.computeFlexTime(dailyBookingInstance). There I want to get the current persisted entry from DailyBooking (from the database): DailyBooking currentEntry = DailyBooking.findByUserAndDate(daily...
Christian
1

votes
3

answer
113

Views

Sorting on nullable fields in GORM

I'm trying to figure out how to sort on multiple fields in Grails 3, one of which may or may not be null. I have this Book domain: class Book { String title String sortTitle static constraints = { title blank: false sortTitle nullable: true } } Books with titles like "The Peripheral" have a sortTitl...
Johan Svensson
1

votes
1

answer
1.1k

Views

[B cannot be cast to java.sql.Blob

This is my domain class class TimesheetSubmission { Date submissionDate=new Date() String foreman String shift String jobId Date date byte[] xmlSubmission String xmlResponse static constraints = { submissionDate nullable: false foreman nullable: false shift nullable: false jobId nullable: false date...

View additional questions