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).
ProblemI 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