-->
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.  [ 1 post ] 
Author Message
 Post subject: How to map postgresql domain type datatype?
PostPosted: Sun Jul 25, 2010 11:42 pm 
Newbie

Joined: Sun Jul 25, 2010 11:13 pm
Posts: 1
Hi,

First of all I am quite new to hibernate and if the question has been discussed somewhere else please let me know (I did a search but found nothing).

Problem
I am using hibernate 3.5.3 (with annotations) with PostgreSQL 8.4.4 RDBMS for my project.

Inside my PostgreSQL database, I have a table called "Address" as
Code:
create table Address (
      id serial primary key,
                ...
      addressType AddressType not null,
      addressDescription text,
      isActive boolean not null
);


Where the AddressType datatype is defined as
Code:
-- address categories
create type AddressType as enum
   ('User','Biller','Institution');


Now I used hibernate-tools 3.2.4 to generate my POJO classes and here is the Address.java
Code:
/**
* Address generated by hbm2java
*/
@Entity
@Table(name = "address", schema = "public")
@SequenceGenerator(name = "address_id_seq", sequenceName = "address_id_seq")
public class Address implements java.io.Serializable {
   
   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "address_id_seq")
   @Column(name = "id")
   private int id;

   private String addresscountry;
   ...
   private String addresstype;
   private String addressdescription;
        ...
}


The default generated code had "private Serializable addresstype;" for which I changed it to "private String addresstype;" in order to be able to deserialize the Address object (is this correct?).

Now here comes the problem if I wanted to save Address object to database. Because I have defined "addressType" as type AddressType in PostgreSQL database table and when I try to save the Address POJO with "addressType" as a String datatype, i get the error:
Quote:
...
40297 [http-8080-2] ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: column "addresstype" is of type addresstype but expression is of type character varying
...


How do I solve this problem, preferably by using annotations only(if that is possible)?

Thank you in advance, your help is very much appreciated!

Jimmy


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

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.