Hibernate – GRAILS and PostgreSQL do not generate tables

So I have some simple domain classes, I make sure not to use any PostgreSQL (or any other vendor) reserved words. Executing grails schema-export will generate a DDL, when targeting the same When the database is running, it will execute successfully and create all tables without problems.

However, when running my grails application, I receive the error ERROR: relationship “artist” Doesn’t exist. (The artist is the domain name I tried to create a sample in BootStrap.groovy).

Checking my database, I can see that no tables are created for my domain.

This is my DataSource.groovy:

dataSource {
pooled = true
driverClassName = "org.postgresql.Driver "
dialect = "org.hibernate.dialect.PostgreSQLDialect"
username = "my_username"
password = "my_password"
}
hibernate {
cache .use_second_level_cache = false
cache.use_query_cache = false
cache.region.factory_class ='net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbcreate = "create-drop"
url = "jdbc:postgresql://localhost:5432/dev"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:postgresql://localhost:5432/test"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:postgresql://localhost:5432/prod"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}

I have verified that the credentials (forged above) are valid, the user has permissions, the database is running in the specified location, etc.

What’s there? What am I missing, or any other type of logging, I can enable, may display the error, or help find it?

What I am most interested in is that the ddl generated by schema-export works well. Does grails generate SQL in a different way at runtime, or is there anything that would cause grails to not execute any create statements?

Grails version 2.1.1, PostgreSQL 9.2.1

BootStrap as required:

import my.site.domain.artist .*

class BootStrap {

def init = {servletContext ->
System.out.println(" ")
log.info ("------------------------------------------------ ---")
log.info("BootStrap initializing...")
log.info("-------------------- -------------------------------")
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
log.info("Default TimeZone set to "+ TimeZone.getDefault().displayName)

Artist artist = new Artist(artistName:'Artist Name', shortBio: "Short Bio" , biography: "Bio", url: "/some_artist")

artist.save()
if(artist.hasErrors()) {
log.info(artist. errors)
} else {
log.info("--Artist--")
log.info("dateCreated: "+ artist.dateCreated)
log.info( "lastUpdated: "+ artis t.lastUpdated)
log.info("mediumImageURL: "+ artist.mediumImageURL)
}
}

def destroy = {
}
}

It may be a feature of pgsql and gorm, because it is related to the automatically generated sequence of ID And id is a reserved word in pgsql. Make sure to use something like user_id (with proper table syntax) instead of id in your domain object.

So I have some simple Domain class, I make sure not to use any PostgreSQL (or any other vendor) reserved words. Executing grails schema-export will generate a DDL, when run against the same database, it will execute successfully and create all tables without appearing Problem.

However, when running my grails application, I receive the error ERROR: The relationship “artist” does not exist. (Artist is the domain name I tried to create a sample in BootStrap.groovy ).

Looking at my database, I can see that no tables are created for my domain.

I have enabled all logging for org.hibernate, but nothing Can indicate any problems. The only problem I can see is that there are no log records related to the creation of any tables, only sample queries that seem to be simple choices.

This is my DataSource.groovy:

p>

dataSource {
pooled = true
driverClassName = "org.postgresql.Driver"
dialect = "org.hibernate.dialect.PostgreSQLDialect"< br /> username = "my_username"
password = "my_password"
}
hibernate {
cache.use_second_level_cache = false
cache.use_query_cache = false
cache.region.factory_class ='net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbcreate = "create-drop"
url = "jdbc:postgresql://localhost:5432/dev"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:postgresql://localhost:5432/test"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:postgresql://localhost:5432/prod"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileI dle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}

I have verified The credentials (forged above) are valid, the user has permission, the database is running in the specified location, etc.

Is there anything I am missing, or any other type of logging, I can enable, What is the error may be displayed, or help find it?

What I am most interested in is that the ddl generated by schema-export works well. Does grails generate SQL in a different way at runtime, or is there anything that would cause grails to not execute any create statements?

Grails version 2.1.1, PostgreSQL 9.2.1

BootStrap as required:

import my.site.domain.artist .*

class BootStrap {

def init = {servletContext ->
System.out.println(" ")
log.info ("------------------------------------------------ ---")
log.info("BootStrap initializing...")
log.info("-------------------- -------------------------------")
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
log.info("Default TimeZone set to "+ TimeZone.getDefault().displayName)

Artist artist = new Artist(artistName:'Artist Name', shortBio: "Short Bio" , biography: "Bio", url: "/some_artist")

artist.save()
if(artist.hasErrors()) {
log.info(artist. errors)
} else {
log.info("--Artist--")
log.info("dateCreated: "+ artist.dateCreated)
log.info( "lastUpdated: "+ artist.la stUpdated)
log.info("mediumImageURL: "+ artist.mediumImageURL)
}
}

def destroy = {
}
}

It may be a feature of pgsql and gorm, because it is related to the automatically generated sequence of ID and id is a reserved word in pgsql. Make sure that it is in your Use content like user_id (with appropriate table syntax) instead of id in the domain object.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4449 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.