I can't find a way to map the next sql example (with postgres 8.1.4 custom types
http://www.postgresql.org/docs/8.1/inte ... types.html )
CREATE TYPE PHONETYPE AS (
country VARCHAR,
area VARCHAR,
number VARCHAR
);
CREATE TABLE CLIENTS (
id INT4 NOT NULL,
companyname VARCHAR NOT NULL,
...
mobile PHONETYPE NULL,
phone PHONETYPE NOT NULL,
...etc
);
I tried to create a PhoneType extending CompositeUserType but that didn't seemed to work.
My hibernate mapping is
<hibernate-mapping>
<class name="biz.admin.client.dao.Clients" table="clients" schema="public">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="sequence" />
</id>
...
<property name="mobile" type="biz.admin.client.dao.PhoneType">
<column name="mobile" />
</property>
<property name="phone" type="biz.admin.client.dao.PhoneType">
<column name="phone" />
</property>
<property name="fax" type="biz.admin.client.dao.PhoneType">
<column name="fax" />
</property>
...
</class>
</hibernate-mapping>
The error I have
00:38:53,175 DEBUG Configuration:1130 - resolving reference to class: biz.admin.client.dao.Country
00:38:53,175 DEBUG Configuration:1130 - resolving reference to class: biz.mli%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: property mapping has wrong number of columns: biz.admin.client.dao.Clients.mobile type: biz.admin.client.dao.PhoneType
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:984)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
at biz.admin.client.dao.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:60)
at biz.admin.client.dao.HibernateSessionFactory.getSession(HibernateSessionFactory.java:43)
at biz.tests.dao.TestDAO.start(TestDAO.java:41)
at biz.tests.dao.TestDAO.main(TestDAO.java:37)
Using hibernate 3.1.3 and postgres 8.1.4
I am not sure that creating a CompositUserType is the right way to go for mapping custom sql types, is it? As it is not a composition of several columns. But still I need to work with that legacy database.
Should I post my complete code of my PhoneType also?