Quantcast

The database returned no natively generated identity value

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

The database returned no natively generated identity value

Salvador Benimeli
Hello,

I'm new to grails. I'm using DB2 express-C database and an the simpliest example from Grails in Action book. I get always the same Runtime Exception when I try to insert values from a form using scaffolding:


Error 500: org.springframework.orm.hibernate3.HibernateSystemException: The database returned no natively generated identity value; nested exception is org.hibernate.HibernateException: The database returned no natively generated identity value
Servlet: grails
URI: /hubbub/grails/profile/save.dispatch
Exception Message: The database returned no natively generated identity value
Caused by: org.springframework.orm.hibernate3.HibernateSystemException: The database returned no natively generated identity value; nested exception is org.hibernate.HibernateException: The database returned no natively generated identity value
Class: script1253120408390
 

I don't have any idea why I get this runtime error. I know that is DB2 specific because when using with hsqldb works fine. Any one could help me??

Thanks in advance. 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: The database returned no natively generated identity value

trags
This post was updated on .
Hello Salvador, I'm also new to Grails, and having the same issue. I wish I could just tell you to naviagate to "Hosting Grails to Your Legacy DB" ( http://jasonrudolph.com/blog/2006/06/20/hoisting-grails-to-your-legacy-db/ ), because Mr. Rudolph addresses this issue exactly. Unfortunately, it seems to be dated, and the code can't look like that anymore. I tried to copy this approach and this is how far I have gotten. Modify DataSource.groovy: dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "pswd"
}
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
//dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://localhost/grailstutorial"
}
}
test {
dataSource {
//dbCreate = "update"
url = "jdbc:mysql://localhost/grailstutorial"
}
}
production {
dataSource {
//dbCreate = "update"
url = "jdbc:mysql://localhost/grailstutorial"
}
}
}
Modify Employee.groovy: class Employee {
String id
String firstName
String lastName
Date startDate

String toString() { "${this.class.name} : $id" }

static mapping = {
table "employees"
version false
columns {
id column: "employee_id", generator: "assigned"
firstName column: "first_name"
lastName column: "last_name"
startDate column: "start_date"
}
}

static constraints = {
id(maxSize:8,null:false,unique:true)
}
}
Finally, add this to create.gsp (in the view/employee directory. I placed it just before the section for firstName) <tr class="prop">
<td valign="top" class="name">
<label for="id">Employee ID:</label>
</td>
<td valin="top" class="value ${hasErrors(bean:employeeInstance,field:'id','errors')}"> <input type="text" id="id" name="id" value="${fieldValue(bean:employeeInstance,field:'id')}"/>
</td>
</tr>
Now it all works up to the point where Mr. Rudolph states "Success", and I get the same failure that you see ("The database returned no natively generated identity value"). I hope someone else posts the last little point I missed, so I can get it to work. Regards, Thomas
Salvador Benimeli wrote
Hello, I'm new to grails. I'm using DB2 express-C database and an the simpliest example from Grails in Action book. I get always the same Runtime Exception when I try to insert values from a form using scaffolding: *Error 500:* org.springframework.orm.hibernate3.HibernateSystemException: The database returned no natively generated identity value; nested exception is org.hibernate.HibernateException: The database returned no natively generated identity value *Servlet:* grails *URI:* /hubbub/grails/profile/save.dispatch *Exception Message:* The database returned no natively generated identity value *Caused by:* org.springframework.orm.hibernate3.HibernateSystemException: The database returned no natively generated identity value; nested exception is org.hibernate.HibernateException: The database returned no natively generated identity value *Class:* script1253120408390 I don't have any idea why I get this runtime error. I know that is DB2 specific because when using with hsqldb works fine. Any one could help me?? Thanks in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: The database returned no natively generated identity value

trags
Hello Salvador, I think I just found the "missing link" for getting this to work. The tutorial will work if you add one line to EmployeeController.groovy. It should look like:

def save = {
def employeeInstance = new Employee(params)
employeeInstance.id = params.id // Here is the magic
if(!employeeInstance.hasErrors() && employeeInstance.save()) {
flash.message = "Employee ${employeeInstance.id} created"
redirect(action:show,id:employeeInstance.id)
}
else {
render(view:'create',model:[employeeInstance:employeeInstance])
}
}

If you explicitly assign the id from the params copy of the same variable just before you save, it seems to all be better.
I also added the port number for MySQL to the datasource url lines. They now look like.
url = "jdbc:mysql://localhost:3306/grailstutorial"

Regards,
Thomas
trags wrote
Hello Salador, I'm also new to Grails, and having the same issue. I wish I could just tell you to naviagate to "Hosting Grails to Your Legacy DB" ( http://jasonrudolph.com/blog/2006/06/20/hoisting-grails-to-your-legacy-db/ ), because Mr. Rudolph addresses this issue exactly. Unfortunately, it seems to be dated, and the code can't look like that anymore. I tried to copy this approach and this is how far I have gotten. Modify DataSource.groovy: dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "pswd"
}
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
//dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://localhost/grailstutorial"
}
}
test {
dataSource {
//dbCreate = "update"
url = "jdbc:mysql://localhost/grailstutorial"
}
}
production {
dataSource {
//dbCreate = "update"
url = "jdbc:mysql://localhost/grailstutorial"
}
}
}
Modify Employee.groovy: class Employee {
String id
String firstName
String lastName
Date startDate

String toString() { "${this.class.name} : $id" }

static mapping = {
table "employees"
version false
columns {
id column: "employee_id", generator: "assigned"
firstName column: "first_name"
lastName column: "last_name"
startDate column: "start_date"
}
}

static constraints = {
id(maxSize:8,null:false,unique:true)
}
}
Finally, add this to create.gsp (in the view/employee directory. I placed it just before the section for firstName) <tr class="prop">
<td valign="top" class="name">
<label for="id">Employee ID:</label>
</td>
<td valin="top" class="value ${hasErrors(bean:employeeInstance,field:'id','errors')}"> <input type="text" id="id" name="id" value="${fieldValue(bean:employeeInstance,field:'id')}"/>
</td>
</tr>
Now it all works up to the point where Mr. Rudolph states "Success", and I get the same failure that you see ("The database returned no natively generated identity value"). I hope someone else posts the last little point I missed, so I can get it to work. Regards, Thomas
Salvador Benimeli wrote
Hello, I'm new to grails. I'm using DB2 express-C database and an the simpliest example from Grails in Action book. I get always the same Runtime Exception when I try to insert values from a form using scaffolding: *Error 500:* org.springframework.orm.hibernate3.HibernateSystemException: The database returned no natively generated identity value; nested exception is org.hibernate.HibernateException: The database returned no natively generated identity value *Servlet:* grails *URI:* /hubbub/grails/profile/save.dispatch *Exception Message:* The database returned no natively generated identity value *Caused by:* org.springframework.orm.hibernate3.HibernateSystemException: The database returned no natively generated identity value; nested exception is org.hibernate.HibernateException: The database returned no natively generated identity value *Class:* script1253120408390 I don't have any idea why I get this runtime error. I know that is DB2 specific because when using with hsqldb works fine. Any one could help me?? Thanks in advance.
Loading...