HI,
I'm not able to put information in a table from a xml data file when I have a a structure of style one-to-many. I have not create java classes. I'm working only with the entity-name. See the following sample to understand my problem.
first: database schema (postgres)
/*==============================================================*/
/* DBMS name: PostgreSQL 7.3 */
/* Created on: 2006-03-31 09:14:35 */
/*==============================================================*/
/*==============================================================*/
/* Table: ACTIVITE */
/*==============================================================*/
create table ACTIVITE (
code_activite CHAR(6) not null,
nature CHAR(1) not null,
groupe CHAR(2) not null,
lieu CHAR(3) not null,
max_etudiant INT4 not null,
constraint PK_ACTIVITE primary key (code_activite, nature, groupe)
);
/*==============================================================*/
/* Table: BLOC */
/*==============================================================*/
create table BLOC (
code_activite CHAR(6) not null,
nature CHAR(1) not null,
groupe CHAR(2) not null,
bloc_id INT4 not null,
jour VARCHAR(128) null,
heure_debut TIME null,
heure_fin TIME null,
horaire_fixe CHAR(1) null,
no_local VARCHAR(16) null,
local_fixe CHAR(1) null,
constraint PK_BLOC primary key (code_activite, nature,groupe, bloc_id)
);
alter table BLOC
add constraint A_HORAIRE foreign key (code_activite, nature, groupe)
references ACTIVITE (code_activite, nature, groupe)
on delete restrict on update restrict;
second : xml data to import :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<horaire>
<activites>
<activite code_activite="AMC600" nature="1" groupe="01" lieu="SHE" max_etudiant="99999">
<blocs_horaires>
<bloc_horaire jour="ME" heure_debut="08:30" heure_fin="11:30" horaire_fixe="O" no_local="D7-3015" local_fixe="O"/>
<bloc_horaire jour="JE" heure_debut="08:30" heure_fin="11:30" horaire_fixe="O" no_local="D7-3015" local_fixe="O"/>
</blocs_horaires>
</activite>
<activite code_activite="AMC600" nature="2" groupe="01" lieu="SHE" max_etudiant="99999">
<blocs_horaires>
<bloc_horaire jour="ME" heure_debut="13:30" heure_fin="14:30" horaire_fixe="O" no_local="D7-3015" local_fixe="O"/>
<bloc_horaire jour="ME" heure_debut="08:30" heure_fin="11:30" horaire_fixe="O" no_local="D7-3015" local_fixe="O"/>
<bloc_horaire jour="JE" heure_debut="08:30" heure_fin="11:30" horaire_fixe="O" no_local="D7-3015" local_fixe="O"/>
</blocs_horaires>
</activite>
</activites>
</horaire>
third: hibernate mapping file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="horaire">
<class entity-name="activite" table="activite" >
<composite-id>
<key-property name="code_activite" column="code_activite" node="@code_activite" type="string"/>
<key-property name="nature" column="nature" node="@nature" type="string"/>
<key-property name="groupe" column="groupe" node="@groupe" type="string"/>
</composite-id>
<property name="lieu" column="lieu" not-null="true" node="@lieu" type="string"/>
<property name="max_etudiant" column="max_etudiant" not-null="true" node="@max_etudiant" type="integer"/>
<list name="blocs_horaires" table="bloc" >
<key>
<column name="code_activite" not-null="true"/>
<column name="nature" not-null="true"/>
<column name="groupe" not-null="true"/>
</key>
<index column="bloc_id"/>
<element type="string" column="jour" node="bloc_horaire" />
</list>
</class>
</hibernate-mapping>
with this example, i have no problem to send data into ACTIVITE table. But I can't send all informations into BLOC table. When I use element, hibernate permits me only one tag element and it refuses to take attribute information from node (element node must not be an attribute: @jour). For this moment the only thing can i do is to change my xml data file to have one element in BLOC_HORAIRE and this element is sent into one field of BLOC table. Although the key and the field bloc_id is sent to BLOC table correctly.
If i use a one-to-many, hibernate wants absolutely a java class define for a BLOC, but same with this class, I'm not able to put information to the BLOC table
Maybe someones have suggest for me.
thank you everybody.
note: English is not my first language
|