gorm

Grails memory leakage for bulk upload - HibernatePersistenceContextInterceptor

ε祈祈猫儿з 提交于 2019-12-13 18:40:23
问题 I am using Quartz job to do some backend processing, which result into bulk upload to database. I am explicitly clearing up the session as given below. class MyService { def sessionFactory static transactional = false def runJob() { def collectionOfDomain = [] for { collectionOfDomain.add(someData) if(collectionOfDomain.size() == 200) { SomeDomain.saveAll(collectionOfDomain) sessionFactory.currentSession.flush() sessionFactory.currentSession.clear() collectionOfDomain.clear() } } } } My

Soft delete an entity in Grails with Hibernate Filters Plugin

南笙酒味 提交于 2019-12-13 15:01:08
问题 I was looking for a way to avoid deleting my users from DB, but instead to mark them as deleted and don't bring them back in queries. I found this plugin http://grails.org/plugin/hibernate-filter, which was a great tool for the task. But when I tried to implement my solution, I passed trought same problems whose solutions wheren't (or I was not able to find) on internet. So, next, I describe the way that I solve the problem of soft delete. 回答1: In this example I will make my class User to

Grails validation of a list objects

青春壹個敷衍的年華 提交于 2019-12-13 13:19:24
问题 I'm trying to get grails to validate the contents of a List of objects, might be easier if I show the code first: class Item { Contact recipient = new Contact() List extraRecipients = [] static hasMany = [ extraRecipients:Contact ] static constraints = {} static embedded = ['recipient'] } class Contact { String name String email static constraints = { name(blank:false) email(email:true, blank:false) } } Basically what i have is a single required Contact ('recipient'), this works just fine:

Using GORM efficiently to retrieve join data - Grails 2.3

寵の児 提交于 2019-12-13 12:50:52
问题 I have User, and Follow Domain class that construct the Follower, Following relationship like Twitter. When my User visits another User's page, and click on their Follower list. I pop-up the list of the visited person's follower list, and then show a button in front of it that is labeled "Follow" or "Unfollow" depending on if you already following that person. So I do it the following way, but I'm not sure if this is efficient or maybe there is a better way of doing it. In order to make it

How do I sort by a property on a nullable association in Grails?

你离开我真会死。 提交于 2019-12-13 11:50:47
问题 I'm trying to sort a table of data. I have the following domain (paraphrased and example-ified): class Car { Engine engine static constraints = { engine nullable: true // poor example, I know } } class Engine { String name } Here's the controller action that's handling the sort: def myAction = { def list = Car.findAll(params) render(view: 'list', model: [list: list]) } I provision some data such that there are several Cars, some with null engines and others with engines that are not null. I

Grails + GORM: What is the default equals() implementation in GORM?

强颜欢笑 提交于 2019-12-13 11:36:01
问题 When I do domainObj1 == domainObj2 in Grails are the objects compared by ID? If not, how are they compared? 回答1: First, you need to understand that GORM/Grails doesn't do anything special when it comes to equals() . Unless you implement your own equals() on your domain class it will default to the Java/Groovy implementation. Which by default means the variables must point to the same instance. Now, what gets slightly confusing is Hibernate. Hibernate uses an identity map (the first-level

Grails Domain class JSON

六月ゝ 毕业季﹏ 提交于 2019-12-13 10:55:12
问题 I have this controller: respond :Alert.list() It gives: [{id: ..}, {id: ..}] What I want: {"alerts":[{"id":...}. {id:..}]} How do I let the respond make into the format I want? I don't want to have a custom JSON marshaller as my dataset is big. What will be the outcome if I do the following than having a custom marshaller? def o = new JSONObject() def arr = new JSONArray() def a = new JSONObject() alerts.each{ a.put("id",it.id) ... arr.add(a) } o.put("alerts",arr) respond o 回答1: Try it like

Grails Domain: How to access parent domain data?

倖福魔咒の 提交于 2019-12-13 08:48:19
问题 I have a parent child domain structure, and I want access parent domain data in child domain for validator. For example in the code example below, child1 has a variable 'name' and for validator purpose I need child2 data. How can I achieve this situation? I have domain structure like this: class Parent{ Child child1 Child child2 static mapping = { child1 lazy:false child2 lazy:false } } class Child{ String name // some other variables static belongsTo = [parent:Parent] static constraints = {

Grails grailApplication.controllerClasses sort controller by package

你。 提交于 2019-12-13 07:41:31
问题 I have the following code that grabs all controllers, sorts it, and outputs in li tags: <g:each var="c" in="${grailsApplication.controllerClasses.sort { it.fullName } }"> <li<%= c.logicalPropertyName == controllerName ? ' class="active"' : '' %>> <g:link controller="${c.logicalPropertyName}">${c.naturalName}</g:link> </li> </g:each> I have a need to filter out controllers by package i.e. grab controller from a certain package. For example: com.app.module.mars.controller.HelloController com

How to have multiple One-to-One relationships between three domain classes

醉酒当歌 提交于 2019-12-13 07:18:48
问题 As a follow up question to this, I want to have a User domain class which has an optional one-to-one relationship with BasicProfile domain class, User being the owner which may or may not have a profile. I have this part figured out. What I also want is an optional one-to-one relationship between the AcademicProfile domain class and the User , AcademicProfile being the owner, such that an AcademicProfile may or may not have a User . When I try to replicate this the way I did the first one-to