Title: GORM properties and Postgres fields is domain data type
Tags: java;grails;jpa;jdbc;grails-orm
Question: 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'75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0regclass),
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
Comment: I tried changing it integer and it didn't work.

Comment: 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'75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0regclass),
username "General Name" NOT NULL,
password "General Name" NOT NULL,
CONSTRAINT userprofile_pkey PRIMARY KEY (iduserprofile)
WITH (
OIDS=FALSE

Comment: 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.

Comment: 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'75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0regclass), and with the same domain object I am able to validate it


Here is another answer: 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.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:07/11/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><grails><jpa><jdbc><grails-orm>', 'Title': 'GORM properties and Postgres fields is domain data type', 'ViewCount': 359, 'id': 17584000, 'user_AboutMe': '', 'user_AccountId': 2649313.0, 'user_DisplayName': 'Dinesh', 'user_Reputation': 1.0, 'user_Views': 10.0, 'user_id': 2291397.0}}