Questions tagged [gorm]

1

votes
2

answer
88

Views

Joint queries through foreign key

I have the following two models: File and Session, and a single session could have many File objects (one-to-many). type Session struct { gorm.Model Name string `json:'name,omitempty'` IsCurrent bool `json:'is_current'` Files []File `gorm:'foreignkey:SessionID...
TonyGW
1

votes
1

answer
29

Views

Can I create a custom criteria query like

I have a legacy PostgreSql table that contains columns with multiple values. I want to select rows that contain any of the values in my search. -- Example query select * from stuff where ARRAY['Value A', 'Value X'] && regexp_split_to_array(thing, '\|'); Can I generate this type of where condition fr...
user1452701
1

votes
1

answer
310

Views

Grails Unit Test fails: String-based queries like [executeQuery] are currently not supported in this implementation of GORM

There are other questions on SO about this, but they are pretty old and none offer solutions to my issue. I'm getting the following error from a unit test: java.lang.UnsupportedOperationException: String-based queries like [executeQuery] are currently not supported in this implementation of GORM. Us...
beechovsky
1

votes
2

answer
95

Views

Grails 3 saving mongoDB document with both _id and id

We noticed an issue after an upgrade to grails 3 that we were saving mongoDB documents with both _id and id. (example document below) How do we stop the saving of id? This happens for every collection the application creates and updates documents for. { '_id' : ObjectId('5b0ed1b710b3641a98aaee63'),...
David B
1

votes
1

answer
123

Views

Grails Hibernate GORM, Multi-Tenancy with one-to-one relationship

Cloned the code from the tutorial : Database per Tenant Multi-Tenancy I went into the completed project and began playing around with things. I understand how the application is resolving tenant ids and connecting to varying datasources without difficulty. What is leaving me scratching my head is ho...
HumbleWebDev
1

votes
0

answer
144

Views

Postgres foreign key on delete constraint

Been following the guide on http://gorm.io/docs/belongs_to.html trying to get simple foreign keys setup, however, I can't find any info on using ON CASCADE or ON DELETE. On http://doc.gorm.io/database.html#migration under the Add Foreign Key section it does make use of ON DELETE and ON CASCADE, how...
Greg Miller
1

votes
0

answer
234

Views

gorm don't find a column field with quotes

Here is my code : package main import ( 'github.com/jinzhu/gorm' _ 'github.com/jinzhu/gorm/dialects/postgres' 'time' 'fmt' ) func (Rank) TableName() string { return 'Score_rank' } // Overriding Column Name type Rank struct { Id int64 `gorm:'column:id'` DateCreation time.Time `gorm:'column:...
user462794
1

votes
1

answer
63

Views

Grails GORM hasMany association inconsistent with MongoDB, When try to fetch child Records,it fetches the record sometimes and doesn't fetch sometimes

Below is the domain class Author which has a one-to-many association with Book. When trying to fetch Author, sometimes will get the associated collection of Book domain object and sometimes returns null. Any thoughts on why it is inconsistent? class Author { static mapWith = 'mongo' String name stat...
Mukesh Singh
1

votes
0

answer
35

Views

GORM is not persisting the changes of an object

I have a service class that is responsible for managing Project entity (simple things for now). @Transactional class ProjectService { UserService userService ... @Publisher(ProjectEvent.PROJECT_UPDATED) Project updateById(Long id, ProjectCommand command, Long updatedById) { User updatedBy = userServ...
1

votes
0

answer
24

Views

Restrict the execution of same GORM object in groovy

I' am new in groovy.in my project I get the data from db using GORM object. When Ever I call the object for data it execute multiple time.I have no Idea why it is executing. After getting the data using the same object when I see the hibernate log there is more then execution of the same object. for...
mohan
1

votes
2

answer
52

Views

Use dynamic finders with list of Object IDs

With the given class structure class MyObject { Status status; } class Status { Integer id; } I want to use dynamic finders to query based on a list of Status ID values. What I want to be able to do is something like this MyObject.findAllByStatusInList([1,2,3]); This does not work though because my...
Raymond Holguin
1

votes
0

answer
248

Views

MS SQL datetime representation in go-gorm

Title says it all. I'm using gorm (golang orm) to connect to a MS SQL db. time.Time gets me datetime2 which is a different dataType. Any suggestions? Structure: type ( ACDepartements struct { DEPTID int `gorm:'column:DEPTID;primary_key;not null;'` DEPTNAME string...
Trody
1

votes
2

answer
85

Views

GORM: Change of inherited field not isDirty()?

After modifying an inherited many-to-one relationship field the change cannot be detected using isDirty() or similar checks. How can I detect the change without manually checking the field? I have already attempted to use @DirtyCheck, however this only works for simple fields, such as lookupId. @Di...
bigfatony
1

votes
3

answer
341

Views

Grails 3.3.6 Does not come with GORM Configured?

I had to upgrade a grails plugin from 2.3.11 to 3.3.6. When I was testing the finished port I noticed errors on my GORM queries. If I recall, in grails 2 GORM already came with it. Is that not the case in grails 3.3.6 ? What do I need to do to enable GORM? I will mention that I am using a SQL Server...
Bmoe
1

votes
0

answer
83

Views

How does gorm determine which table to use?

I want connect to SQL SERVER using gorm. I've read documentation how to create new record in table. There is a code: user := User{Name: 'Jinzhu', Age: 18, Birthday: time.Now()} db.NewRecord(user) // => returns `true` as primary key is blank db.Create(&user) db.NewRecord(user) // => return `false` af...
1

votes
0

answer
112

Views

How to update the nested tables in sql using gorm?

Here the code is written in Go. I am using two tables where one table has a foreign key that refers to the other table's primary key. Let's say I have a database as following struct defined: type User struct{ ID uint `gorm:'primary_key;column:id'` Name string `gorm:'column:name'` Place place PlaceID...
manav Jain
1

votes
0

answer
33

Views

nested exception is org.hibernate.HibernateException: Missing column in GORM many to many mapping

The table is already created inside the database using another software, I need to convert the mapping with GORM, So the column name and type has already been created. Class Customer{ static hasMany = [ reservationClienti:ReservationSource] static mapping = { sort('id') table name: 'clienti'//, sche...
Madhvendra Thakur
1

votes
0

answer
56

Views

How do I stop GORM from sorting my preload by ID?

In my database I have a users table, joined via a many-to-many table to schools. A school has many jobs. I'm trying to return all the schools and their jobs for a specific user. This is my code so far: var user User err := db.Where('id = ?', userID).Preload('Schools') .Preload('Schools.Jobs', func(d...
LaserJesus
1

votes
1

answer
68

Views

MissingPropertyException in SpringSecurityService in my Grails 3.3.8 application

Using the grails spring security plugin (3.2.3) I have an app with the standard domain classes that are created using this guide: https://grails-plugins.github.io/grails-spring-security-core/3.2.x/index.html#tutorials It has the following classes specified in the tutorial: Role.groovy, UserRole.groo...
georgy3k
1

votes
0

answer
55

Views

Raw query not populating one-to-many association

I have the following sqlite query: SELECT orders.id , orders.shop_id , tv.total_value , line_items.id , line_items.product_id , line_items.order_id , line_items.description , line_items.quantity , products.price AS 'line_items.price' FROM orders JOIN line_items ON line_items.order_id = orders.id JOI...
Sean
1

votes
0

answer
29

Views

GORM createCriteria and the result set do not return the same results

In the createCriteria using max:50 and offset:0, I have a projection like below projections { sum('downloads') sum('clicks') groupProperty('site') groupProperty('link') groupProperty('device') } totalCount returns 939 rows and the result set returns 8. How I can get the no of resultset? I tried resu...
1

votes
1

answer
92

Views

Connect localhost Postgres database

I just installed for the first time Postgres on my computer and I was able to connect my database through JetBrains DataGrip. but when I am trying to connect the database through my app (using gorm) it doesn't work... jdbc:postgresql://localhost:5432/postgres and i did try to connect this way: postg...
Nir Berko
1

votes
1

answer
190

Views

Cant connect to postgres (password authentication failed for user - docker)

I was trying to run docker compose to set up nginx, golang server and postgresql. The problem is that I can't connect to the database: Initially, I was trying to connect to postgres with this instruction: db, err = gorm.Open('postgres', 'host=db port=5432 user=sigbrian password=example sslmode=disab...
Joaco Terniro
1

votes
1

answer
58

Views

Grails 3.1 - Can't find codec for domain class

I am not able to convert domain class into Basic DB object. Below is my code: def update_val class_object.class.withNewSession { MongoCodecSession m -> update_val = m.pendingUpdates.find { it.key.name == d.class.getName() }.value[0]nativeEntry.regions[0].'${instance.getDbKey()}'[0] } On below f...
1

votes
1

answer
33

Views

Connect different database(Dynamic) in single application in grails

I have a grails application having version 3.3.+ in before versions like 2.2.1 etc i can connect database on run time with session.reconnect(connect) function (hibernate) but in new version this line throw exception like 'Cannot manually reconnect unless Connection was originally supplied by user'...
Arun
1

votes
0

answer
52

Views

Extra Column in self-referencing model

I just started to use Gorm and I am encountering troubles to define a model. I have succeeded in creating a join table by following the doc example for self-referencing model: type User struct { gorm.Model Friends []*User `gorm:'many2many:friendships;association_jointable_foreignkey:friend_id'` } Th...
OgliWanFabi
1

votes
1

answer
71

Views

grails.gorm.transactions.Transactional not rolling back

I am having issues rolling back a transaction in my service layer with the following: Grails 3.3.8 GORM 6.1.10.RELEASE I have the following service method: import grails.gorm.transactions.Transactional @Transactional(rollbackFor = Exception.class) class TestingService { void testServiceMethod(List f...
georgy3k
1

votes
0

answer
32

Views

Grails: Session and Transactions not working properly (fails or detach after single flush)

I am using grails 2.4.0 and trying to bulk upload data through csv file, i am using withNewSession for this work and using this session to upload the data in database. while i call a save function it flushes automatically and thats it,only single record is saved and the program dont run after it. i'...
Zaryab baloch
1

votes
1

answer
119

Views

Design of lambda API written in Go

I need help with the design of my API that is written in Go. That's the file structure: database/ database.go middlewares/ authentication.go models/ pageview services/ pageviews/ create/ main.go show/ main.go serverless.yml By now I only have the pageviews service. Let me show you what's inside the...
MrBear
1

votes
0

answer
27

Views

belongTo self in gorm

I'm trying to establish a belongsTo relationship on the same table. But I'm unable to succeed. I didn't find any easily understandable examples on the Internet. type Role struct { gorm.Model Name string Description string Inclusive bool Controller *Role `gorm:'foreignkey:controller;association_forei...
Khorwin
1

votes
1

answer
167

Views

How to get sum of salary column from table GORM

I am using PostgreSQL and golang to write a backend. I am having a problem to get a sum of salary column. This is my code: func GetSalarySum(c echo.Context) error { db, err := gorm.Open('postgres', 'host=localhost port=5433 user=postgres dbname=testone password=root sslmode=disable') checkError(err)...
gauravsbagul
1

votes
1

answer
277

Views

How to configure application.yml for mysql using Gorm in micronaut

I am trying to make a CRUD application in micronaut and groovy, i am using hibernate and GORM for validation,save,delete etc with mySql database and @Transactional. While i run the application it runs fine but there is no tables initialized in mysql. While sending the Post request to save the Data...
Zaryab baloch
1

votes
0

answer
44

Views

MongoDB WildCard query taking too much time using Grails

MongoDB v4.0.2 Grails 3.3.5 I've more than 20 Millions of records stored in a collection. I'm trying to wildcard search in that collection like as follows... def personList = Person.collection.find(['vehicleNumber': ['$regex':/.*GJ18AD.*/] ]).sort(['datetime':-1]) Index on Person Collection db.pers...
Vivek Buddhadev
1

votes
1

answer
57

Views

Mapping Clob type in grails domain class with postgresql text type

I am using the code is working for Derby, MySQL, Oracle but it's throwing error while using with PostgreSQL I'm getting error org.hibernet.exception.DataException could not execute the query. I'm getting a solution to map text with String. But nowhere solution is for map text with Clob in domain cl...
Ajay Kumar Jaiswal
0

votes
0

answer
3

Views

grails create criteria non unique object error if wrapped in withNewSession

I have criteria that looks like this //Inventory.withNewSession{ Set inventory=Inventory.withCriteria{ setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) inventoryDetail{ eq('userAdded',true) } ... } //} If I wrap that in a withNewSession I get duplicate key and non unique object in the session err...
user2782001
1

votes
1

answer
35

Views

Grails 3 / GORM kick out single records from result

I'm trying to achieve the following in an ajax call from a text field to a Controller: Get a Motor list according to the criteria from the text field Kick out certain values out of the resulting list: Those Motors contained inside Otherdomain (and meeting a certain criteria) shall not be part of th...
Michael
1

votes
1

answer
39

Views

Why do I receive an error when I consult data in my Micronaut Gorm application?

I have a simple application in Mironaut with three entities, Customer, Contact and Loans. Customer has a 1 to many relationship with Contact and Loans. I test with Grails / Gorm and it works fine. I have a DataLoader class that works well and creates all entities with their relationships. /****** Co...
Gerardo Nuñez
1

votes
0

answer
27

Views

Using a custom Oracle DB sequence in Grails id generation

I have a Grails (v. 3.3.8) app with some scaffolded views which are based on tables in my Oracle 12c database. It all works well with a naive incremental ID generator but in order for it to work 100% according to the specification, I need to have it take the ID's from the database's sequences. For e...
Straightfw
1

votes
1

answer
32

Views

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

I am new to Go 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 foll...
Giwi
1

votes
0

answer
77

Views

Gorm create only if entry does not exists

I have the following structs: type Project struct { gorm.Model Title string Description string Skills []Skill `gorm:'many2many:project_skills;'` } type Skill struct { gorm.Model Name string } this is how I create the project (and then Gorm creates automatically the skills): create := rs.D...
Nir Berko

View additional questions