I've created a column check constraint in table Comentari using:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Aquest es el mapping de la classe Comentari a la taula comentari. Els atributs data, client i hotel
formen la clau primaria de la taula i es mapejen a les columnes data, dniClient i nomHotel. Client i hotel
son a la vegada relacions un a molts amb Client i Hotel els atributs avaluacio i descripcio es mapejen a
les columnes avaluacio i descripcio. La RI 13 finalment s'ha implementat a capa de dades amb un check a la
columna avaluacio. S'han hagut d'utilitzar les squencies d'escapada < i > enlloc dels caracters
< i > perque sino els parser les confon amb inicis i final d'etiquetes XML.
Autor: Marc Mauri Alloza-->
<hibernate-mapping>
<class name="com.bonshotels.DomainLayer.DomainModel.Comentari" table="Comentari">
<composite-id>
<key-property name="data" type="java.util.Date" column="data"/>
<key-many-to-one name="client" class="com.bonshotels.DomainLayer.DomainModel.Client" column="dniClient"/>
<key-many-to-one name="hotel" class="com.bonshotels.DomainLayer.DomainModel.Hotel" column="nomHotel"/>
</composite-id>
<property name="avaluacio" type="int" >
<column name="avaluacio" check="avaluacio >= 0 AND avaluacio <= 10" />
</property>
<property name="descripcio" type="java.lang.String">
<column name="descripcio" />
</property>
</class>
</hibernate-mapping>
As has been suggested to me in:
viewtopic.php?f=1&t=1014098But when I run the app the SQL generated by hbm for HSQLDB doesn't contain any CHECK.
Code:
/*C2*/SET SCHEMA PUBLIC
CONNECT USER SA
SET AUTOCOMMIT FALSE
SET AUTOCOMMIT TRUE
SET AUTOCOMMIT FALSE
DISCONNECT
/*C3*/SET SCHEMA PUBLIC
CONNECT USER SA
SET AUTOCOMMIT FALSE
SET AUTOCOMMIT TRUE
alter table Comentari drop constraint FK1130822E80CB43C2
alter table Comentari drop constraint FK1130822E8107C28F
alter table DescompteFixe drop constraint FK33F006425A9BBB1A
alter table DescompteVariable drop constraint FKE128E8CE5A9BBB1A
alter table Habitacio drop constraint FK971001C2752D6C0
alter table Habitacio drop constraint FK971001C80CB43C2
alter table Hotel drop constraint FK42AD19447CB8342
alter table Hotel drop constraint FK42AD1942784AF08
alter table PreuTipusHabitacio drop constraint FK8A404EB55A9BBB1A
alter table PreuTipusHabitacio drop constraint FK8A404EB580CB43C2
alter table PreuTipusHabitacio drop constraint FK8A404EB5E0FBAC8C
alter table Reserva drop constraint FKA49CA498EFE0EAC0
alter table Reserva drop constraint FKA49CA4988107C28F
alter table SenseDescompte drop constraint FKB754F0645A9BBB1A
drop table BonsHotels if exists
drop table CategoriaHotel if exists
drop table Client if exists
drop table Comentari if exists
drop table DescompteFixe if exists
drop table DescompteVariable if exists
drop table Habitacio if exists
drop table Hotel if exists
drop table IEstrategiaCalculPreu if exists
drop table Poblacio if exists
drop table PreuTipusHabitacio if exists
drop table Reserva if exists
drop table SenseDescompte if exists
drop table TipusHabitacio if exists
create table BonsHotels (id bigint generated by default as identity (start with 1), quotaFixa float, quotaVariable float, primary key (id))
create table CategoriaHotel (nom varchar(255) not null, primary key (nom))
create table Client (dni varchar(255) not null, nom varchar(255), cognoms varchar(255), email varchar(255), primary key (dni))
create table Comentari (data timestamp not null, dniClient varchar(255) not null, nomHotel varchar(255) not null, avaluacio integer, descripcio varchar(255), primary key (data, dniClient, nomHotel))
create table DescompteFixe (idEstrategia bigint not null, descompteFixe float, primary key (idEstrategia))
create table DescompteVariable (idEstrategia bigint not null, descompteVariable float, primary key (idEstrategia))
create table Habitacio (numero integer not null, nomHotel varchar(255) not null, tipusHabitacio varchar(255) not null, primary key (numero, nomHotel))
create table Hotel (nom varchar(255) not null, descripcio varchar(255), nomCategoria varchar(255) not null, nomPoblacio varchar(255) not null, primary key (nom))
create table IEstrategiaCalculPreu (id bigint generated by default as identity (start with 1), primary key (id))
create table Poblacio (nom varchar(255) not null, primary key (nom))
create table PreuTipusHabitacio (nomTipusHabitacio varchar(255) not null, nomHotel varchar(255) not null, preu float, idEstrategia bigint not null, primary key (nomTipusHabitacio, nomHotel))
create table Reserva (idReserva varchar(255) not null, dataInici timestamp, dataReserva timestamp, dataFi timestamp, preuTotal float, numHabitacio integer not null, nomHotel varchar(255) not null, dniClient varchar(255) not null, primary key (idReserva))
create table SenseDescompte (idEstrategia bigint not null, primary key (idEstrategia))
create table TipusHabitacio (nom varchar(255) not null, capacitat integer, descripcio varchar(255), primary key (nom))
alter table Comentari add constraint FK1130822E80CB43C2 foreign key (nomHotel) references Hotel
alter table Comentari add constraint FK1130822E8107C28F foreign key (dniClient) references Client
alter table DescompteFixe add constraint FK33F006425A9BBB1A foreign key (idEstrategia) references IEstrategiaCalculPreu
alter table DescompteVariable add constraint FKE128E8CE5A9BBB1A foreign key (idEstrategia) references IEstrategiaCalculPreu
alter table Habitacio add constraint FK971001C2752D6C0 foreign key (tipusHabitacio) references TipusHabitacio
alter table Habitacio add constraint FK971001C80CB43C2 foreign key (nomHotel) references Hotel
alter table Hotel add constraint FK42AD19447CB8342 foreign key (nomCategoria) references CategoriaHotel
alter table Hotel add constraint FK42AD1942784AF08 foreign key (nomPoblacio) references Poblacio
alter table PreuTipusHabitacio add constraint FK8A404EB55A9BBB1A foreign key (idEstrategia) references IEstrategiaCalculPreu
alter table PreuTipusHabitacio add constraint FK8A404EB580CB43C2 foreign key (nomHotel) references Hotel
alter table PreuTipusHabitacio add constraint FK8A404EB5E0FBAC8C foreign key (nomTipusHabitacio) references TipusHabitacio
alter table Reserva add constraint FKA49CA498EFE0EAC0 foreign key (numHabitacio, nomHotel) references Habitacio
alter table Reserva add constraint FKA49CA4988107C28F foreign key (dniClient) references Client
alter table SenseDescompte add constraint FKB754F0645A9BBB1A foreign key (idEstrategia) references IEstrategiaCalculPreu
SET AUTOCOMMIT FALSE
DISCONNECT
My hbm2ddl.auto is create.
Am I missing something? Is column check generation for HSQLDB unsupported? Is this a bug?
Thank you.