Quantcast
Channel: Spring Community Forums - Grails
Viewing all articles
Browse latest Browse all 40

How to Map a Simple Oracle "Legacy" Table into a Grails Domain Class?

$
0
0
Hi, everyone. I am a very experienced java developer, and a somewhat experienced Spring developer, but am new to Grails.

I'm trying to create a simple one-table one-class grails prototype app that reads from a simple pre-existing Oracle table.

I can see that the grails app is connecting to the database ok, but when I code the Datasource.groovy as dbCreate="update", it wants to add a new hibernate_sequence to the table, and gets this exception:

Code:

C:\opt\grailsWorkspace\myapp>grails run-app
Welcome to Grails 1.3.7 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: C:\opt\grails

Base Directory: C:\opt\grailsWorkspace\myapp
Resolving dependencies...
Dependencies resolved in 1154ms.
Running script C:\opt\grails\scripts\RunApp.groovy
Environment set to development
  [groovyc] Compiling 2 source files to C:\opt\grailsWorkspace\myapp\tar
get\classes
  [delete] Deleting directory C:\Users\bethridge\.grails\1.3.7\projects\myapp\tomcat
Running Grails application..
2013-04-25 14:41:10,410 [main] ERROR hbm2ddl.SchemaUpdate  - Unsuccessful: creat
e sequence hibernate_sequence
2013-04-25 14:41:10,410 [main] ERROR hbm2ddl.SchemaUpdate  - ORA-01031: insuffic
ient privileges

Thank goodness I didn't have the Oracle privilege to do such. Otherwise, I imagine I would have just messed up a perfectly good Oracle table for our whole team! (The Grails documentation in my Grails book was not very clear on that point.)

If I change to dbCreate="validate", then I get this exception:
Code:

org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'messageSource': Initialization of bean failed; nested exception is org.s
pringframework.beans.factory.BeanCreationException: Error creating bean with nam
e 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while
setting bean property 'sessionFactory'; nested exception is org.springframework.
beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto
ry': Invocation of init method failed; nested exception is org.hibernate.Hiberna
teException: Missing sequence or table: hibernate_sequence
        at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
        at grails.web.container.EmbeddableServer$start.call(Unknown Source)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:15
8)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
        at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:2
80)
        at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
        at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
        at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
        at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
        at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
        at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
        at RunApp$_run_closure1.doCall(RunApp.groovy:33)
        at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:427)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:415)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.executeTargets(Gant.groovy:590)
        at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name 'transactionManager': Cannot resolve reference to bean 'sessio
nFactory' while setting bean property 'sessionFactory'; nested exception is org.
springframework.beans.factory.BeanCreationException: Error creating bean with na
me 'sessionFactory': Invocation of init method failed; nested exception is org.h
ibernate.HibernateException: Missing sequence or table: hibernate_sequence
        ... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name 'sessionFactory': Invocation of init method failed; nested exc
eption is org.hibernate.HibernateException: Missing sequence or table: hibernate
_sequence
        ... 23 more
Caused by: org.hibernate.HibernateException: Missing sequence or table: hibernat
e_sequence

....and the error makes sense, but the bottom line is that this is a PRE-EXISTING and in-production table, so I don't want Grails/Hibernate to create a new hibernate_sequence at all. The table already has a perfectly good primary key. I just want grails/hibernate to map to the existing primary key.

I've poked around my Grails books, the internet and this forum, but I don't see how to do this yet.

In general, how am I supposed to configure for a simple legacy database scenario in Grails?

Ben Ethridge

Viewing all articles
Browse latest Browse all 40

Trending Articles