Archive | Grails RSS feed for this section

generate-all No domain class found for.. error in grails

22 Jun

Short Story: Provide fully qualified domain class name(class name with the package) to the generate-all command

Long Story:

If you have recently moved from pre-1.3 to latest grails version(1.3.2 as of today) and suddenly you have started getting this error

No domain class found for name Book. Please try again and enter a valid domain class name

on generate-all command


grails generate-all Book

then don’t panic. As of grails-1.3.2, when you create a new domain class, it is generated in a package. For example, in my case my Book.groovy is generated under mylib package(mylib is the name of my application)

generate-all command requires you provide fully qualified class names. This is true for even older versions like 1.1.1.

Issue this command instead


grails generate-all mylib.Book

I wish they made this point clear in their documentation at http://grails.org/doc/latest/ref/Command%20Line/generate-all.html

Grails EHCache Settings

11 Jun

We have configured Ehcache as second level hibernate cache for our project. This post is for Grails 1.1.1 projects. In the later version of grails, the configuration can be little different. Here are the steps. (It is quite some time when I did the actual configuration. Let me know if I missed something)

i)

First of all we have put ehcache.xml in grails-app/conf directory. Our config file looks like this.  You may modify the config based on your preferences. To learn more about this settings go to http://ehcache.org/documentation/configuration.html


<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="ehcache.xsd">
 <defaultCache
    maxElementsInMemory="1000"
    eternal="false"
    timeToIdleSeconds="3600"
    timeToLiveSeconds="3600"
    overflowToDisk="false"
    diskPersistent="false"
    diskExpiryThreadIntervalSeconds="120"
    memoryStoreEvictionPolicy="LRU"
 />

 <cache name="org.hibernate.cache.UpdateTimestampsCache"
        maxElementsInMemory="10000"
        timeToIdleSeconds="300"
 />

 <cache name="org.hibernate.cache.StandardQueryCache"
        maxElementsInMemory="10000"
        timeToIdleSeconds="300"
 />

</ehcache>

ii) Modify the cache provider class in your DataSource.groovy to org.hibernate.cache.EhCacheProvider like this

hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='org.hibernate.cache.EhCacheProvider'
}

iii) Now to fine-tune your cache setting, go to individual domain classes for which you want to enable ehcache and add the following mapping closure with cache true

class Employee {
    String name
    ........
    ........
    static constraints = {
        ....
    }

    static mapping = {
        cache true
    }
}

iv) If you want your query to be cached, you can configure it similarly with cache true clause

		def employeeList = Employee.createCriteria().list() {
			or {
				......
			}
			order(".....", "...")
			cache true
		}

For further reading to to http://ehcache.org/documentation/grails.html

Creating Acegi Users in a script

6 Oct

We are using Acegi plugin for Authentication and Authorization in Grails. We had to create users in bulk using MySql script. We have to know the encrypted password for each user, corresponding to the clear text password to insert in the database. (Acegi encrypts the password before storing it in the database).

I came across this nice post http://stackoverflow.com/questions/1472431/acegi-password-encryption

I was also thinking that Acegi must be using MD5, but after reading this post realized that it is SHA1 encryption.

You can get the sha1 encrypted password by issuing this command

echo -n password | openssl sha1

For eg. if your password is admin you can find encrypted password by issuing this command

echo -n admin | openssl sha1

Grails – Plugin file not found for plugin project

10 Sep

If you have just renamed your Grails plugin project and getting this error “Plugin file not found for plugin project” and wondering – “What’s going on?”

Consider this. Grails is based on DRY principle. Convention over configuration. By convention, the plugin descripor file should end in the word “GrailsPlugin”

Most likely it would have happened that you wanted to rename AbcDef grails plugin to say Abc plugin

In the process, instead of renaming AbcDefGrailsPlugin.groovy file in your plugin root directoy to AbcGrailsPlugin.grooy, you might have mistakenly renamed it to just AbcPlugin.groovy. Since the word GrailsPlugin was not in the name, it was considered as the normal project instead of Plugin project.

If you look inside $GRAILS_HOME/scripts/_GrailsPluginDev.groovy file, you can see the following code snippet


metadataFile.name,
 "*GrailsPlugin.groovy",

In short, the solution is to rename the file and the class defined inside it to AbcGrailsPlugin.groovy

Grails Maven Integration

10 Sep

Note: Information provided in this post may get outdated soon, because Grails, it’s plugin and dependencies gets updated very frequently.

Today I was trying to integrate my existing grails application with Maven. I had hard time with it. I referred to the following information

The pom generated by the plugin was of Grails 1.1 and I was using grails 1.1.1 therefore I had to make the following changes in my pom.xml


<dependency>
 <groupId>org.grails</groupId>
 <artifactId>grails-crud</artifactId>
 <version>1.1.1</version>
 </dependency>
 <dependency>
 <groupId>org.grails</groupId>
 <artifactId>grails-gorm</artifactId>
 <version>1.1.1</version>
 </dependency>

Since I was using MySql I had to add this too


<dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <version>3.1.14</version>
 </dependency>

Also you need to add this


<dependency>
 <groupId>org.tmatesoft.svnkit</groupId>
 <artifactId>svnkit</artifactId>
 <version>1.2.3.5521</version>
 <scope>runtime</scope>
 </dependency>

If you are not using Acegi then this is all you need to do for Maven integration. If you are using Acegi then you might have to make some more changes. In my case, I was getting ClassNotFoundException  for net.sf.ehcache.CacheException. I had to manually copy ehcache-1.3.0.jar from $MAVEN_REPOSITORY_HOME/repository/net/sf/ehcache/1.3.0 to $GRAILS_PROJECT_HOME/plugins/acegi/lib. It solved my issue and I was successfully able to run my grails app using mvn grails:run-app

As I said before, information in this post may get outdated very soon. But it solved my problem and it might solve your too.

Grails – No such property: save for class

8 Sep

I suddenly started getting this message in my grails app. I don’t know the root cause of the problem. But for me the cause of the problem was removal of some fields and renaming of certain fields in domain class. If you have rename and/or removed some fields then make sure you follow these steps

  1. Stopped the running grails application. Changes made in the domains, controllers and other grails-app artifacts sometimes doesn’t get updated while application is running
  2. Remove and update the reference of the removed or renamed fields from the gsp, constraints block of domain, any other static blocks in referenced domains, messages.properties and other property files.
  3. If you are not using in-memory db(HSQL) and using mysql or any other persistent database, then corresponding columns of the renamed/removed old fields are not deleted from database. If it does not affect the already existing data in DB then drop the corresponding table. When you restart application, grails will create the table for you again. If your table has foreign key reference, then drop the database altogether and create new DB and grant all privileges to the user used by Grails.
  4. If the above steps don’t work for you and you are using grails 1.1.1 then try doing MyDomainClass.get(-1) in your Bootstrap.groovy. See http://grails.1312388.n4.nabble.com/No-such-property-save-for-class-td1389894.html

This solved my No such property: save for class issue. YMMV. In your case, the cause may be different.

Null message in Grails

18 Aug

I had a domain object

class Project{
    String projectTitle
    Rso rso
}

Where Rso itself is another domain object.

Both projectTitle and rso could not be blank or null.
when I tried
project.projectTitle.blank message in messages.properties, it worked

but
project.rso.null was not working.
I was trying project.rso.null because the default message was mapped as default.null.message.

Then someone suggested me to use
project.rso.nullable and it worked.

Running grails at some specific port

7 Jul

By default, jetty will run the application at port 8080, but if you want to run the application at some specific port, for example 8085 you should use

grails -Dserver.port=8085 run-app

Grails : No domain class found for name domain-class-name . Please try again and enter a valid domain class name

23 Jun

Sometimes, even if you create domain objects in grails you get the error that No domain class found.
I am not sure why this happens because I am new to Grails and still learning. But the following steps work for me

i) Stop all the running grails app ctrl+C
ii) grails clean
iii) Now try grails generate-all domain-class-name

This generally works for me. I will update this post if I find the root cause of the problemSom

Beginning Groovy and Grails

1 May

In the last session on April 13, 2009 on Jazz and Rational Team Concert at TCJUG , I have won the book Beginning Groovy and Grails: From Novice to Professional (Beginning from Novice to Professional) in the lucky draw.

Beginning Groovy and Grails

This is happening second time in the row that I have attended JUG meeting with Groovy message. In my last meeting the topic of discussion itself was groovy and this time around, it is the book. The message is loud and clear. Looks like everyone has started taking Groovy seriously. People consider it as gen-next Java language. After all, Groovy is not something which poises itself to compete with Java language. In fact it builds itself over the Java language. You run groovy programs on JVM. While relieving developers of many of the pains which comes with java, groovy provides many powerful features, missing and long sought in Java.
Having said that, I am still a doubtful thomas, when it comes to new technology. To build a secure, scalable, robust application, I would not put my bets on Grails. At least for now.

By the way the presentation slides for Jazz are not there yet on TCJUG website. Check http://jazz.net/ for more details.
Jazz is also a wonderful framework address the concerns of the entire life-cycle of project development. From requirement analysis to design and development; from testing to maintenance; from project management to project change management; it is built on the vision to provide one -stop- shop for all the needs.
Rational Team Concert is the product built on Jazz framework. The speaker has demonstrated many cool features of RTC. It integrates IDE, testing environment, team collaboration, version and cofiguration management, quality management in the other words absolutely every tool we use daily during the software lifecycle. It integrates all these tools at one place. PM will have the clear and accurate picture what is going on with the status and updates of each and every developer, tester will now what fixes developers are working on etc etc. Worth checking out. As far as I remember, the speaker said that this product is relatively new but it has achieved record sales in its category in IBM.

Follow

Get every new post delivered to your Inbox.