0

I just want to know if it possible to map GORM properties to fields in Postgres table where the data type is the postgres domain. I am getting an error when it is validating. Thanks

Domain class:

class Userprofile {

long iduser
String username

static mapping = {
    datasource 'ALL'
    id name: 'iduser'
    version false
}
}

Table in postgres:

security.userprofile
(

iduser "Primary Key Id" NOT NULL DEFAULT nextval('security.userprofile_seq'::regclass),

username "General Name" NOT NULL,

)

CREATE DOMAIN "Primary Key Id" AS bigint;

CREATE DOMAIN "General Name" AS character varying(100) COLLATE pg_catalog."default";

I have set the dbCreate to "validate" in datasource and i was getting this error message when validating the db:

Caused by HibernateException: Wrong column type in userprofile for column iduser. Found: primary, expected: int8

4
  • Not sure about this but I think if you change long iduser to Integer iduser(change data type to integer) in your domain class, then it should validate. Commented Jul 11, 2013 at 14:13
  • I tried changing it integer and it didn't work. Commented Jul 11, 2013 at 19:59
  • Do you have existing table in the database, and you have to connect your app with it?, because I have tried to have a table with iduser: bigint-> default: nextval('user_profile_check_iduser_seq'::regclass), and with the same domain object I am able to validate it :) Commented Jul 12, 2013 at 8:30
  • Yes i am able to connect my app to the database and retrieves data if i don't set the dbCreate to "validate" in the datasource. I just leave it blank. This is how my table looks like: CREATE TABLE security.userprofile ( iduserprofile "Primary Key Id" NOT NULL DEFAULT nextval('security.userprofile_seq'::regclass), username "General Name" NOT NULL, password "General Name" NOT NULL, CONSTRAINT userprofile_pkey PRIMARY KEY (iduserprofile) ) WITH ( OIDS=FALSE ); Commented Jul 13, 2013 at 4:22

1 Answer 1

3

I am not entirely familiar with GORM validations. There might have to be some additional logic set up to map in the validation rules. However one thing about your error jumped out at me right away.

Caused by HibernateException: Wrong column type in userprofile for column iduser. Found: primary, expected: int8

Now, your domain isn't even "primary" but rather "Primary Key Id." So GORM is not only failing to map it, but is failing even to find the right label.

The first thing I would look at doing is change your naming convention so that it is all lower cases and _'s. The domains become primary_key_id and general_name. See how much further this gets you and then explore what else you have to do to get GORM to handle it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.