gorm

Grails 3 - return list in query result from HQL query

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 07:00:55
问题 I have a domain object: class Business { String name List subUnits static hasMany = [ subUnits : SubUnit, ] } I want to get name and subUnits using HQL, but I get an error Exception: org.springframework.orm.hibernate4.HibernateQueryException: not an entity when using: List businesses = Business.executeQuery("select business.name, business.subUnits from Business as business") Is there a way I can get subUnits returned in the result query result as a List using HQL? When I use a left join, the

Access Relationship Table in Grails

☆樱花仙子☆ 提交于 2019-12-13 05:09:55
问题 I have the following domains classes: class Posts{ String Name String Country static hasMany = [tags:Tags] static constraints = { } } class Tags{ String Name static belongsTo = Posts static hasMany = [posts:Posts] static constraints = { } String toString() { "${TypeName}" } } Grails creates an another table in the database i.e. Posts_Tags. My requirement is: E.g. 1 post has 3 tags. So, in the Posts_Tags table there are 3 rows. How can I access the table Posts_Tags directly in my code so that

how to make tablePerHierarchy false and use discriminator?

这一生的挚爱 提交于 2019-12-13 05:02:46
问题 A question like what I need is asked here but it's answer is not satisfying what I need. I have classes like this : abstract class A{ String a } class B extends A{ String b } class C extends A{ String c } I want to have a table for each class, so I add tablePerHierarchy and set it false like this: abstract class A{ String a static mapping = { tablePerHierarchy false } } but when I run the program and it creates a database there are no discriminator, and I want to query table A and find out if

How to prevent unwanted update of persisted objects?

别来无恙 提交于 2019-12-13 04:58:03
问题 I have a Load class and a Cargo class. An instance of Load contains an instance of Cargo . class Load { Cargo cargo } class Cargo { String name BigDecimal cost } Lets say that the name of an instance of Cargo is "rock" and the cost is "11.11". Now I use this instance of Cargo to create an instance of Load . Now that the instance of Load has been created I don't want it's "cargo" to change. For instance, if I change the price of "rock" to "22.22" I don't want the price of the "cargo" in my

How to get and use a transient instance?

こ雲淡風輕ζ 提交于 2019-12-13 04:54:18
问题 I'm just trying to use a transient instance of a domain class in a controller. The transient instance is essentially a cross-product of two persistent instances, and I don't need or want to persist it. However, I am still getting a TransientObjectException. Is there no way to instantiate an object for a little bit just for convenience and then throw it away without persisting it? This is grails 2.2.0. Thanks! Okay , adding some codes: The class in particular that I'm dealing with is Warranty

Duplicates to be allowed in the mapping table for many to many relationship with extra column

扶醉桌前 提交于 2019-12-13 02:55:10
问题 I have two domain classes with many to many relationship with extra column.I created below domain classes by following the logic from the forums and still face an issue in saving the data in additional domain class.Roylaty is the additional column to save the value in the mapping table. Below are the 3 domain classes: class AuthorBook implements Serializable { Author author Book book String royalty boolean equals(other) { if (!(other instanceof AuthorBook)) { return false } other.author?.id =

Grails 2.4.2: Strange cascading save behaviour in nested transactions

浪尽此生 提交于 2019-12-13 02:32:38
问题 I have some strange behaviour with incorrect cascading of the save in my object graph. Maybe it has something to do with nested transaction, but maybe not. Here are my 3 domain classes: Station.groovy class Station { /** Dependency injected {@link de.hutapp.tapandknow.system.SettingsService}.*/ def settingsService static hasMany = [localizedStations: LocalizedStation, stationIdentifiers: AbstractStationIdentifier] } LocalizedStation.groovy class LocalizedStation { /** Delete-cascade from the

Grails unique compound key issues

血红的双手。 提交于 2019-12-13 02:08:11
问题 Given a GORM class: class PriceSheet { Client client Population population Product product RevenueModelType modelType BigDecimal price static constraints = { client(unique: ['population', 'product', 'modelType']) } } I'm wanting a PriceSheet to be saved/updated only if the client, population, product and modelType are unique. (There should only be one pricesheet item for combination of client, population, product and modelType). The key is being created in mySQL. My issue is the grails

how set start value for auto increment in grails

一曲冷凌霜 提交于 2019-12-13 02:06:03
问题 I am using my custom auto increment key in my domain class using static mapping = { id generator: 'increment', name: 'personId' } Is it possible to start the auto increment from a particular value , say start from 100 ? 回答1: You can set the initial value of the autoincrement by using the org.hibernate.id.enhanced.SequenceStyleGenerator generator. This generator takes the parameter initial_value , which will be the the value of your first id . (And after that, it will increment by 1, just like

Using findBy in transactional context

社会主义新天地 提交于 2019-12-12 20:42:14
问题 Given: controller PersonController with a @Transactional action save service PersonService with a method populateProperties(PersonInstance) being called from the controller action I'd like to populate personInstance properties based on some data already persisted in the database, like this: def personLookupData = PersonLookupData.findByUsername(personInstance.username) personInstance.firstName = personLookupData.firstName The findByUsername method flushes the hibernate session and in order to