Reputation: 175
I have a domain class that has a number of member variables. Let's say it looks like this:
class Foo {
String BARID
int NUM1
}
When I try to persist the object, Hibernate throws an exception ("org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type for class") complaining that my Id should be a Long type instead of a String... but I don't want BARID to actually be an id in the table, it is simply named that way for unrelated reasons. I need that variable to appear as BARID both in the object as well as in the database, for purposes of downstream compatibility (other programs require that it be called BARID).
Clearly hibernate is trying to be fancy under the hood and figure out which fields are ids. How can I tell hibernate that contrary to what it might think, this is NOT an id field?
Update: I realize the variable case is non-standard, but i would prefer to keep them as-is, unless that is the reason this is broken. (For the record, I tried switching to all lowercase "barid" and I got the exact same exception).
SOLUTION: I used Jeff's suggested solution of explicitly defining a mapping block:
static mapping = {
id generator: 'increment'
}
Upvotes: 1
Views: 118
Reputation: 3938
It sounds like you still want the normal id field anyway so if you just add it to the domain object it should be fine I tested this on Grails 2.3.1
class Foo {
Long id
String BARID
int NUM1
}
Also if you don't want to use that method you can always use the mapping block to configure the id. Doc Here
Upvotes: 1