-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Define new sql-type
PostPosted: Mon May 30, 2016 1:32 am 
Newbie

Joined: Mon May 30, 2016 1:19 am
Posts: 2
I've created a UserType for mapping List fields to Postgres ARRAY columns. The returned SQL type is Types.ARRAY:

Code:
   @Override
   public int[] sqlTypes() {
      return new int[] { Types.ARRAY };
   }


When I start my app, I get the following exception:

Code:
    org.hibernate.MappingException: No Dialect mapping for JDBC type: 2003


I can get around this by specifying e.g. sql-type="text[]" in my .hbm.xml file, but I'd rather not have to do that. Is there a way to return an SQL type from the UserType? Or is there some other way to map JDBC type 2003 to text[]?

I've created a related question on StackOverflow (with a bounty :)
http://stackoverflow.com/questions/3747 ... n-usertype


Top
 Profile  
 
 Post subject: Re: Define new sql-type
PostPosted: Mon May 30, 2016 6:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can try this solution.


Top
 Profile  
 
 Post subject: Re: Define new sql-type
PostPosted: Thu Jun 02, 2016 8:24 pm 
Newbie

Joined: Mon May 30, 2016 1:19 am
Posts: 2
Thanks mihalcea_vlad, but that's very close to what I already have, which doesn't work.

I see someone else has tried defining their own type by creating a new dialect:

Code:
public class PostgreSQLDialectArray extends org.hibernate.dialect.PostgreSQLDialect{
    public PostgreSQLDialectArray() {
        super();
        registerHibernateType(Types.ARRAY, "array");
    }
}


But doing that doesn't work, because it results in a statement like this:

Code:
create table foo (bar array);


When in fact the array needs to be typed like this:

Code:
create table foo (bar integer array);


So registerHibernateType can't be used, because it can only map a single Type. It seems to me I need to define new int types for each type of array (float, int, string, etc) and return them from my UserType's sqlTypes function. Is that a reasonable thing to do, or is it too ugly?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.