Thank you for interesting on my problem here is an extract of the mapping file, the field an class are in french.
Whe have an "Habitation" that extend "Bien" an a generator for the if of "Bien".


During insert of "Habitation" it seems that the generator Bien_id is increment twice so the foreign key
between Habitation and Bien is not respected.


I have also attached some file at this e-mail extract from a component to access the database.
DataAccess.java gather the method using Castor and TestAnnonce is a junit testcase that
try a to add an advertising concerning house in the database so it create a new Habitation
object.


I hope there's enought stuff to analyse my problem.


<key-generator name="SEQUENCE" alias="Bien_id">
<param name="sequence" value="REFGEN" />
</key-generator>
<class name="interIMMO.Bien" identity="reference" key-generator="Bien_id"> <map-to table="bien"/>
<field name="reference" type="int" required="true">
<sql name="reference" type="numeric" />
</field>
<field name="code_postal" type="string" required="true">
<sql name="code_postal" type="varchar" />
</field>
<field name="pays" type="string" required="true">
<sql name="pays" type="varchar" />
</field> <field name="description" type="string" required="true">
<sql name="description" type="varchar"/>
</field>
<field name="date_de_disponibilite" type="java.util.Date">
<sql name="date_de_disponibilite" type="date"/>
</field>
<field name="distance_commerces" type="java.lang.Float">
<sql name="distance_commerces" type="numeric"/>
</field>
<field name="distance_ecole" type="java.lang.Float">
<sql name="distance_ecole" type="numeric"/>
</field>
<field name="distance_transports" type="java.lang.Float">
<sql name="distance_transports" type="numeric"/>
</field>
<field name="revenu_cadastral" type="java.lang.Integer">
<sql name="revenu_cadastral" type="numeric"/>
</field>
<field name="Categorie" type="interIMMO.Categorie" required="true">
<sql name="categorie_bien" />
</field>
<field name="Adresse_bien.commune" type="string">
<sql name="adr_commune" type="varchar" />
</field>
<field name="Adresse_bien.numero" type="string">
<sql name="adr_numero" type="varchar" />
</field>
<field name="Adresse_bien.rue" type="string">
<sql name="adr_rue" type="varchar" />
</field>
<field name="habitation" type="boolean">
<sql name="habitation" type="char[no]"/>
</field>
<field name="terrain" type="boolean">
<sql name="terrain" type="char[no]"/>
</field>
</class>
<class name="interIMMO.Habitation" extends="interIMMO.Bien" identity="reference">
<map-to table="habitation" />
<field name="reference" type="int" required="true">
<sql name="reference" type="numeric" />
</field>
<field name="annee_de_construction" type="integer">
<sql name="annee_de_construction" type="numeric"/>
</field>
<field name="caveExiste" type="java.lang.Boolean">
<sql name="cave_existe" type="char[no]"/>
</field>
<field name="Cave.surface" type="integer">
<sql name="cave_surface" type="numeric"/>
</field>
<field name="cuisineExiste" type="java.lang.Boolean">
<sql name="cuisine_existe" type="char[no]"/>
</field>
<field name="Cuisine.surface" type="integer">
<sql name="cuisine_surface" type="numeric"/>
</field>
<field name="Cuisine.type" type="string">
<sql name="cuisine_type" type="varchar"/>
</field> <field name="double_vitrage" type="java.lang.Boolean">
<sql name="double_vitrage" type="char[no]"/>
</field>
<field name="etat_interieur" type="string">
<sql name="etat_interieur" type="varchar"/>
</field>
<field name="JardinExiste" type="java.lang.Boolean">
<sql name="jardin_existe" type="char[no]"/>
</field>
<field name="Jardin.orientation" type="string">
<sql name="jardin_orientation" type="varchar"/>
</field>
<field name="Jardin.superficie" type="integer">
<sql name="jardin_superficie" type="numeric"/>
</field>
<field name="livingExiste" type="java.lang.Boolean">
<sql name="living_existe" type="char[no]"/>
</field>
<field name="living.surface" type="integer">
<sql name="living_surface" type="numeric"/>
</field>
<field name="meuble" type="java.lang.Boolean">
<sql name="meuble" type="char[no]" />
</field>
<field name="neuf" type="java.lang.Boolean">
<sql name="neuf" type="char[no]"/>
</field>
<field name="nombre_d_etages" type="java.lang.Integer">
<sql name="nombre_d_etages" type="numeric"/>
</field>
<field name="nombre_de_chambres" type="java.lang.Integer" required="true">
<sql name="nombre_de_chambres" type="numeric"/>
</field>
<field name="nombre_de_facades" type="java.lang.Integer">
<sql name="nombre_de_facades" type="numeric"/>
</field> <field name="Parking.nb_exterieurs" type="java.lang.Integer">
<sql name="parking_nb_exterieurs" type="numeric"/>
</field>
<field name="Parking.nb_interieurs" type="java.lang.Integer">
<sql name="parking_nb_interieurs" type="numeric"/>
</field>
<field name="parlophone" type="java.lang.Boolean">
<sql name="parlophone" type="char[no]"/>
</field> <field name="salle_a_mangerExiste" type="java.lang.Boolean">
<sql name="salle_a_manger_existe" type="char[no]"/>
</field> <field name="Salle_a_manger.surface" type="java.lang.Integer">
<sql name="salle_a_manger_surface" type="numeric"/>
</field>
<field name="Sanitaires.nb_salles_de_bain" type="java.lang.Integer">
<sql name="sanitaires_nb_salles_de_bain" type="numeric"/>
</field>
<field name="Sanitaires.nb_salles_de_douche" type="java.lang.Integer">
<sql name="sanitaires_nb_salles_de_douche" type="numeric"/>
</field>
<field name="Sanitaires.nb_toilettes" type="java.lang.Integer">
<sql name="sanitaires_nb_toilettes" type="numeric"/>
</field>
<field name="surface_habitable" type="java.lang.Integer">
<sql name="surface_habitable" type="numeric"/>
</field>
<field name="teledistribution" type="java.lang.Boolean">
<sql name="teledistribution" type="char[no]"/>
</field>
<field name="terrasseExiste" type="java.lang.Boolean">
<sql name="terrasse_existe" type="char[no]"/>
</field>
<field name="Terrasse.surface" type="java.lang.Integer">
<sql name="terrasse_surface" type="numeric"/>
</field>
<field name="type_de_chauffage" type="java.lang.String">
<sql name="type_de_chauffage" type="varchar"/>
</field>
<field name="vacances" type="java.lang.Boolean">
<sql name="vacances" type="char[no]"/>
</field>
<field name="appartement" type="boolean">
<sql name="appartement" type="char[no]"/>
</field>
</class>


/* Generated class from DB-MAIN on 2004/6/24 at 13:59 */
package interIMMO;


/**
 * Les habitations sont des biens comprenant notamment les biens de cat�gorie " 
Appartement
 * ", " Maison " et " Loft ". Il faut toujours mentionner le nombre de chambres d'une
 * habitation. 
*/
public class Habitation extends Bien  {
        private int _nombre_de_chambres;
        private Integer _surface_habitable;
        private Boolean _neuf;
        private Boolean _meuble;
        private Boolean _vacances;
        private Integer _annee_de_construction;
        private Integer _nombre_d_etages;
        private Boolean _teledistribution;
        private Boolean _parlophone;
        private Boolean _double_vitrage;
        private String _etat_interieur;
        private String _type_de_chauffage;
        private Integer _nombre_de_facades;
        private boolean _appartement;
        private Jardin _Jardin;
        private Terrasse _Terrasse;
        private Living _Living;
        private Cave _Cave;
        private Salle_a_manger _Salle_a_manger;
        private Cuisine _Cuisine;
        private Sanitaires _Sanitaires;
        private Parking _Parking;

/**
 * Nombre de chambres de l'habitation
*/

        public void setNombre_de_chambres(int nombre_de_chambres) {
                _nombre_de_chambres=nombre_de_chambres;
        }
        public int getNombre_de_chambres(){
                return _nombre_de_chambres;
        }
/**
 * Surface habitable en m�
*/

        public void setSurface_habitable(Integer surface_habitable) {
                _surface_habitable=surface_habitable;
        }
        public Integer getSurface_habitable(){
                return _surface_habitable;
        }
/**
 * Habitation neuve : oui / non
*/

        public void setNeuf(Boolean neuf) {
                _neuf=neuf;
        }
        public Boolean getNeuf(){
                return _neuf;
        }
/**
 * Habitation meubl�e : oui / non
*/

        public void setMeuble(Boolean meuble) {
                _meuble=meuble;
        }
        public Boolean getMeuble(){
                return _meuble;
        }
/**
 * Habitation de vacances : oui / non
*/

        public void setVacances(Boolean vacances) {
                _vacances=vacances;
        }
        public Boolean getVacances(){
                return _vacances;
        }
/**
 * Ann�e de construction de l'habitation
*/

        public void setAnnee_de_construction(Integer annee_de_construction) {
                _annee_de_construction=annee_de_construction;
        }
        public Integer getAnnee_de_construction(){
                return _annee_de_construction;
        }
/**
 * Nombre d'�tages de l'habitation
*/

        public void setNombre_d_etages(Integer nombre_d_etages) {
                _nombre_d_etages=nombre_d_etages;
        }
        public Integer getNombre_d_etages(){
                return _nombre_d_etages;
        }
/**
 * Disponibilit� de la t�l�distribution dans l'habitation : oui / non
*/

        public void setTeledistribution(Boolean teledistribution) {
                _teledistribution=teledistribution;
        }
        public Boolean getTeledistribution(){
                return _teledistribution;
        }
/**
 * Disponibilit� d'un parlophone dans l'habitation : oui / non
*/

        public void setParlophone(Boolean parlophone) {
                _parlophone=parlophone;
        }
        public Boolean getParlophone(){
                return _parlophone;
        }
/**
 * Disponibilit� d'un double-vitrage dans l'habitation : oui / non
*/

        public void setDouble_vitrage(Boolean double_vitrage) {
                _double_vitrage=double_vitrage;
        }
        public Boolean getDouble_vitrage(){
                return _double_vitrage;
        }
/**
 * Etat int�rieur de l'habitation : excellent / bon / � rafra�chir
*/

        public void setEtat_interieur(String etat_interieur) {
                _etat_interieur=etat_interieur;
        }
        public String getEtat_interieur(){
                return _etat_interieur;
        }
/**
 * Type de chauffage de l'habitation : gaz / �lectrique / mazout
*/

        public void setType_de_chauffage(String type_de_chauffage) {
                _type_de_chauffage=type_de_chauffage;
        }
        public String getType_de_chauffage(){
                return _type_de_chauffage;
        }
/**
 * Nombre de fa�ades de l'habitation
*/

        public void setNombre_de_facades(Integer nombre_de_facades) {
                _nombre_de_facades=nombre_de_facades;
        }
        public Integer getNombre_de_facades(){
                return _nombre_de_facades;
        }
        /**
         * Valeur garnie automatiquement par la base de donn�es, cette m�thode 
         * est utilis�e par le composant d'acc�s lui m�me.
         * @param appartement
         */
        public void setAppartement(boolean appartement) {
                _appartement=appartement;
        }
        /**
         * @return true si l'habitation est un appartement
         */
        public boolean getAppartement(){
                return _appartement;
        }
        public void setJardin(Jardin obj) {
                _Jardin=obj;
        }
        public Jardin getJardin(){
                return _Jardin;
        }
        public void setTerrasse(Terrasse obj) {
                _Terrasse=obj;
        }
        public Terrasse getTerrasse(){
                return _Terrasse;
        }
        public void setLiving(Living obj) {
                _Living=obj;
        }
        public Living getLiving(){
                return _Living;
        }
        public void setCave(Cave obj) {
                _Cave=obj;
        }
        public Cave getCave(){
                return _Cave;
        }
        public void setSalle_a_manger(Salle_a_manger obj) {
                _Salle_a_manger=obj;
        }
        public Salle_a_manger getSalle_a_manger(){
                return _Salle_a_manger;
        }
        public void setCuisine(Cuisine obj) {
                _Cuisine=obj;
        }
        public Cuisine getCuisine(){
                return _Cuisine;
        }
        public void setSanitaires(Sanitaires obj) {
                _Sanitaires=obj;
        }
        public Sanitaires getSanitaires(){
                return _Sanitaires;
        }
        public void setParking(Parking obj) {
                _Parking=obj;
        }
        public Parking getParking(){
                return _Parking;
        }       
 public String toString() {
        return "<Habitation: nombre_de_chambres=" +  _nombre_de_chambres +" 
surface_habitable=" +  _surface_habitable +" neuf=" +  _neuf +" meuble=" +  _meuble +" 
vacances=" +  _vacances +" annee_de_construction=" +  _annee_de_construction +" 
nombre_d_etages=" +  _nombre_d_etages +" teledistribution=" +  _teledistribution +" 
parlophone=" +  _parlophone +" double_vitrage=" +  _double_vitrage +" etat_interieur=" 
+  _etat_interieur +" type_de_chauffage=" +  _type_de_chauffage +" nombre_de_facades=" 
+  _nombre_de_facades +" appartement=" +  _appartement +" >";
 }

 //Code non g�n�r�
 /**
  * M�thode permettant de g�r�r l'existance d'un objet cave vide.
  * Methode utilis�e par le composant d'acc�s � la base de donn�es.
  * @param c 
  */
        public void setCaveExiste(Boolean c) {
                try{
                        if(c.equals(Boolean.TRUE) && _Cave==null)
                                _Cave=new Cave();
                        if(c.equals(Boolean.FALSE) && _Cave!=null)
                                _Cave=null;
                }catch (NullPointerException e){
                                _Cave=null;
                }
                
        }
        
        public Boolean getCaveExiste() {                
                if (_Cave==null)
                        return Boolean.FALSE;
                else
                        return Boolean.TRUE;
        }


        public void setCuisineExiste(Boolean c) {
                try{
                        if(c.equals(Boolean.TRUE) && _Cuisine==null)
                                _Cuisine=new Cuisine();
                        if(c.equals(Boolean.FALSE) && _Cuisine!=null)
                                _Cuisine=null;
                }catch (NullPointerException e){
                        _Cuisine=null;
                }
        }
        
        public Boolean getCuisineExiste() {
                if (_Cuisine==null)
                        return Boolean.FALSE;
                else
                        return Boolean.TRUE;
        }
        
        public void setJardinExiste(Boolean c) {
                try{
                        if(c.equals(Boolean.TRUE) && _Jardin==null)
                                _Jardin=new Jardin();
                        if(c.equals(Boolean.FALSE) && _Jardin!=null)
                                _Jardin=null;
                }catch (NullPointerException e){
                        _Jardin=null;
                }
        }
        
        public Boolean getJardinExiste() {
                if (_Jardin==null)
                        return Boolean.FALSE;
                else
                        return Boolean.TRUE;
        }
        
        public void setLivingExiste(Boolean c) {
                try{
                        if(c.equals(Boolean.TRUE) && _Living==null)
                                _Living=new Living();
                        if(c.equals(Boolean.FALSE) && _Living!=null)
                                _Living=null;
                }catch (NullPointerException e){
                        _Living=null;
                }
        }
        
        public Boolean getLivingExiste() {
                if (_Living==null)
                        return Boolean.FALSE;
                else
                        return Boolean.TRUE;
        }
                
        public void setSalle_a_mangerExiste(Boolean c) {
                try{
                        if(c.equals(Boolean.TRUE) && _Salle_a_manger==null)
                                _Salle_a_manger=new Salle_a_manger();
                        if(c.equals(Boolean.FALSE) && _Salle_a_manger!=null)
                                _Salle_a_manger=null;
                }catch (NullPointerException e){
                        _Salle_a_manger=null;
                }
        }
        
        public Boolean getSalle_a_mangerExiste() {
                if (_Salle_a_manger==null)
                        return Boolean.FALSE;
                else
                        return Boolean.TRUE;
        }
        
        public void setTerrasseExiste(Boolean c) {
                try{
                        if(c.equals(Boolean.TRUE) && _Terrasse==null)
                                _Terrasse=new Terrasse();
                        if(c.equals(Boolean.FALSE) && _Terrasse!=null)
                                _Terrasse=null;
                }catch (NullPointerException e){
                        _Terrasse=null;
                }
        }
        
        public Boolean getTerrasseExiste() {
                if (_Terrasse==null)
                        return Boolean.FALSE;
                else
                        return Boolean.TRUE;
        }
 
}

/* Generated class from DB-MAIN on 2004/6/24 at 13:59 */
package interIMMO;


/**
 * Les biens ont une r�f�rence interne � InterIMMO qui les identifie. Il faut �galement
 * pr�ciser leur pays et leur code postal, et en proposer une description. Tout bien
 * appartient � une cat�gorie connue dans le syst�me. Les biens se subdivisent en deux
 * grandes sous-cat�gories distinctes non exhaustives : les habitations et les 
terrains.
*/
public class Bien {
        private int _reference;
        private String _pays;
        private String _code_postal;
        private String _description;
        private Float _distance_ecole;
        private Float _distance_transports;
        private Float _distance_commerces;
        private java.util.Date _date_de_disponibilite;
        private Integer _revenu_cadastral;
        private boolean _terrain;
        private boolean _habitation;
        private Adresse_bien _Adresse_bien;
        private Categorie _Categorie;

/**
 * R�f�rence du bien propos�
 * Il s'agit d'une r�f�rence interne � InterIMMO
 * et permettant d'identifier le bien.
 * Valeur garnie automatiquement par la base de donn�es, cette m�thode 
 * est utilis�e par le composant d'acc�s lui m�me.
*/      
        public void setReference(int reference) {
                _reference=reference;
        }
        
        
        public int getReference(){
                return _reference;
        }
/**
 * Pays dans lequel se trouve le bien propos�
*/

        public void setPays(String pays) {
                _pays=pays;
        }
        public String getPays(){
                return _pays;
        }
/**
 * Code postal du bien propos�
*/

        public void setCode_postal(String code_postal) {
                _code_postal=code_postal;
        }
        public String getCode_postal(){
                return _code_postal;
        }
/**
 * Description du bien propos�
*/

        public void setDescription(String description) {
                _description=description;
        }
        public String getDescription(){
                return _description;
        }
/**
 * Distance du bien propos� par rapport � l'�cole la plus proche (en km)
*/

        public void setDistance_ecole(Float distance_ecole) {
                _distance_ecole=distance_ecole;
        }
        public Float getDistance_ecole(){
                return _distance_ecole;
        }
/**
 * Distance du bien propos� par rapport � l'arr�t des transports en commun le plus 
proche
 * (en km)
*/

        public void setDistance_transports(Float distance_transports) {
                _distance_transports=distance_transports;
        }
        public Float getDistance_transports(){
                return _distance_transports;
        }
/**
 * Distance du bien propos� par rapport au commerce le plus proche (en km)
*/

        public void setDistance_commerces(Float distance_commerces) {
                _distance_commerces=distance_commerces;
        }
        public Float getDistance_commerces(){
                return _distance_commerces;
        }
/**
 * Date de disponibilit� du bien propos�
*/

        public void setDate_de_disponibilite(java.util.Date date_de_disponibilite) {
                _date_de_disponibilite=date_de_disponibilite;
        }
        public java.util.Date getDate_de_disponibilite(){
                return _date_de_disponibilite;
        }
/**
 * Revenu cadastral du bien propos� (en �)
*/

        public void setRevenu_cadastral(Integer revenu_cadastral) {
                _revenu_cadastral=revenu_cadastral;
        }
        public Integer getRevenu_cadastral(){
                return _revenu_cadastral;
        }
        /**
         * Valeur garnie automatiquement par la base de donn�es, cette m�thode 
         * est utilis�e par le composant d'acc�s lui m�me.
         * @param terrain
         */
        public void setTerrain(boolean terrain) {
                _terrain=terrain;
        }
        /**
         * @return true si le bien est un terrain
         */
        public boolean getTerrain(){
                return _terrain;
        }
        
        /**
         * Valeur garnie automatiquement par la base de donn�es, cette m�thode 
         * est utilis�e par le composant d'acc�s lui m�me.
         * @param habitation
         */ 
        public void setHabitation(boolean habitation) {
                _habitation=habitation;
        }
        
        /**
         * @return true si le bien est une habitation
         */
        public boolean getHabitation(){
                return _habitation;
        }
        public void setAdresse_bien(Adresse_bien obj) {
                _Adresse_bien=obj;
        }
        public Adresse_bien getAdresse_bien(){
                return _Adresse_bien;
        }
        public void setCategorie(Categorie obj) {
                _Categorie=obj;
        }
        public Categorie getCategorie(){
                return _Categorie;
        }       
 public String toString() {
        return "<Bien: reference=" +  _reference +" pays=" +  _pays +" code_postal=" + 
 _code_postal +" description=" +  _description +" distance_ecole=" +  _distance_ecole 
+" distance_transports=" +  _distance_transports +" distance_commerces=" +  
_distance_commerces +" date_de_disponibilite=" +  _date_de_disponibilite +" 
revenu_cadastral=" +  _revenu_cadastral +" terrain=" +  _terrain +" habitation=" +  
_habitation +" >";
        }
}

/*
 * Created on 1 juil. 2004
 *
 * FUNDP - Laboratoire d'ing�nierie d'application de base de donn�es    
 */
package tests;

import interIMMO.*;
import junit.framework.TestCase;
import java.util.logging.*;
/**
 * @author jvi
 */
public class TestAnnonce extends TestCase {
        
        private DataAccess data;        
        private static Logger log;
        
        public TestAnnonce(String name) throws Exception {
                super(name);
                data=new DataAccess("../tests/InterImmoDB.xml");
                log = Logger.getLogger("interIMMO.TestUtilisateur_identifie");         
                 
        }
        
        public void testAddAnnonce() {
                log.info("Cr�ation d'un appartement");
                try{
                        data.begin();
                        //Appartement a=new Appartement();
                        Habitation a=new Habitation();
                        a.setCategorie(data.getCategorie("Maison"));
                        a.setAdresse_bien(new Adresse_bien());
                        a.getAdresse_bien().setCommune("Jalhay");
                        a.getAdresse_bien().setNumero("8");
                        a.getAdresse_bien().setRue("Route de Gospinal");
                        a.setCode_postal("4845");
                        a.setPays("Belgique");
                        //a.setAscenseur(Boolean.FALSE);
                        a.setCave(new Cave());
                        a.getCave().setSurface(new Integer(68));
                        a.setDescription("Maison neuve bien situ� avec jolie vue");
                        a.setNeuf(Boolean.TRUE);
                        a.setDate_de_disponibilite(new 
java.text.SimpleDateFormat("yyy-MM-dd").parse("2004-08-29"));
                        a.setAnnee_de_construction(new Integer(2002));
                        a.setCuisine(new Cuisine());
                        a.getCuisine().setSurface(new Integer(12));
                        a.getCuisine().setType("Equip�e");
                        /*
                        a.setImmeuble(new Immeuble());
                        a.getImmeuble().setNombre_d_etages(new Integer(4));
                        a.getImmeuble().setNombre_de_facades(new Integer(4));
                        a.setEtage_du_bien(new Integer(1));
                        */
                        a.setDistance_ecole(new Float(1.2));                    
                        data.create(a);         
                        /*Annonce an=new Annonce();
                        an.setBien(a);
                        Utilisateur_identifie u=data.getUtilisateur_identifie("gpq");
                        an.setContact(u.getContact());
                        an.setType(Annonce.LOCATION);
                        an.setPrix(412);
                        data.create(an);*/
                        data.commit();
                }
                catch (Exception e) {
                        log.log(Level.SEVERE,"Exception", e);
                }
                
        }
}
/*
 * Created on 10 juin 2004
 *
 */

package interIMMO;
import org.exolab.castor.jdo.*;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.persist.spi.Complex;
import java.util.*;

/**
 * Class d'acc�s aux donn�es via des objets persistants.
 * L'utilisation des m�thodes de cette classe n�cessite l'ouverture
 * d'une transaction. Les objets obtenus par les m�thodes de cette classe
 * ne sont persistant que durant la transaction.
 *
 * @author jvi
 */
public class DataAccess {
                
        private String DatabaseFile;
            
    private static final String MappingFile = "InterImmoMapping.xml";

    private Mapping  _mapping;


    private JDO      _jdo;
            
        private Database      db;
        private OQLQuery     oql;
        private QueryResults results;   
            
/**
 * Constructeur initialisant le composant d'acc�s aux donn�es
 * 
 * @param dbFile Le chemin vers le fichier de param�trage de la connexion vers la base 
de donn�es
 * @throws Exception
 */
     public DataAccess(String dbFile) throws Exception {
        // Get the database connection information
        DatabaseFile=dbFile;
        
//               Define the JDO object
                
       _mapping = new Mapping( getClass().getClassLoader() );
       
       _mapping.loadMapping( getClass().getResource( MappingFile ) );

       _jdo = new JDO();
       
       _jdo.setConfiguration( getClass().getResource( DatabaseFile ).toString() );
       _jdo.setDatabaseName( "InterImmo" );       
       db = _jdo.getDatabase();                
        }
    
    /**
     * Acc�s � l'objet Database qui permet entre autre la gestion des transactions
     * @see <a 
href="http://www.castor.org/api/org/exolab/castor/jdo/Database.html";>Interface 
Database</a>
     * @return l'objet repr�sentant la connexion � la base de donn�e
     */ 
    public Database getCurrentDatabase(){
        return db;
    }
    
    /**
     * Acc�s aux donn�es d'un utilisateur identifi� par le login
     * @param login identifiant d'un utilisateur
     * @return L'utilisateur identifi� par son login
     * @throws TransactionNotInProgressException
     * @throws LockNotGrantedException
     * @throws PersistenceException
     */
    public Utilisateur_identifie getUtilisateur_identifie(String login) throws 
TransactionNotInProgressException, LockNotGrantedException, PersistenceException{      
                          
                Utilisateur_identifie ui;               
                try {
                        ui=(Utilisateur_identifie) 
db.load(Utilisateur_identifie.class,login);          
                } catch (ObjectNotFoundException e) {
                        return null;
                }
                ui.setContact(getContact(ui));                                  
                return ui;              
    }

    /**
     * Acc�s aux informations de contact d'un utilisateur identifi�
     * @param u l'utilisateur identifi�
     * @return les informations de contact de l'utilisateur identifi�
     * @throws QueryException
     * @throws TransactionNotInProgressException
     * @throws PersistenceException
     */
        public Contact getContact(Utilisateur_identifie u) throws QueryException, 
TransactionNotInProgressException, PersistenceException {
                String oqlContact= new String("SELECT c FROM interIMMO.Contact c WHERE 
Utilisateur_identifie=$1");
                Contact c;
                                                
                oql = db.getOQLQuery( oqlContact );
                oql.bind(u);
                results = oql.execute();
                if(results.hasMore()){
                        c=(Contact)results.next();
                        
                        return c;
                }
                else{   
                        
                        return null;
                }
        }
        /**
         * Acc�s � une annonce via son identifiant
         * @param ref r�f�rence du bien
         * @param type type de l'annonce (Vente/Location)
         * @return L'annonce identifi�e par son type et la r�f�rence du bien 
         * @throws LockNotGrantedException
         * @throws TransactionNotInProgressException
         * @throws PersistenceException
         */
        public Annonce getAnnonce(int ref, String type) throws 
LockNotGrantedException, TransactionNotInProgressException, PersistenceException{      
  
                try {
                        return (Annonce) db.load(Annonce.class, new Complex(new 
Integer(ref),type));
                } catch (ObjectNotFoundException e) {
                        return null;
                }
        }
        /**
         * Acc�s � toutes les annonces d'un utilisateur identifi�
         * @param u l'utilisateur identifi�
         * @return Enumeration des annonces
         * @throws QueryException
         * @throws TransactionNotInProgressException
         * @throws PersistenceException
         */
        public Enumeration getAnnonces(Utilisateur_identifie u) throws QueryException, 
TransactionNotInProgressException, PersistenceException{
                String oqlAnnonces = new String("SELECT a FROM interIMMO.Annonce a 
WHERE a.Utilisateur_identifie=$1");
                oql = db.getOQLQuery(oqlAnnonces);
                oql.bind(u);
                return oql.execute();
        }
        
        /**
         * Acc�s aux informations d'un terrain
         * @param ref r�f�rence du terrain
         * @return le terrain identifi� par <i>ref</i>
         * @throws TransactionNotInProgressException
         * @throws LockNotGrantedException
         * @throws PersistenceException
         */
        public Terrain getTerrain(int ref) throws TransactionNotInProgressException, 
LockNotGrantedException, PersistenceException {            
                try {
                        return (Terrain) db.load(Terrain.class,new Integer(ref));
                } catch (ObjectNotFoundException e) {
                        return null;
                }
        }
        
        /**
         * Acc�s aux informations d'une habitation (maison, appartement,...) dans le 
cas d'un appartement
         * les donn�es sp�cifiques � la classe appartement ne sont pas accessible.
         * @param ref r�f�rence de l'habitation
         * @return l'habitation identifi�e par <i>ref</i>
         * @throws TransactionNotInProgressException
         * @throws LockNotGrantedException
         * @throws PersistenceException
         */
        public Habitation getHabitation(int ref)  throws 
TransactionNotInProgressException, LockNotGrantedException, PersistenceException {
                try {
                        return (Habitation)db.load(Habitation.class,new Integer(ref));
                } catch (ObjectNotFoundException e) {
                        return null;
                }
        }
        
        /**
         * Acc�s aux informations d'un appartement, les informations h�rit�es de la 
classe habitation sont accessibles �galement.
         * @param ref r�f�rence de l'appartement
         * @return l'appartement identifi� par <i>ref</i>
         * @throws TransactionNotInProgressException
         * @throws LockNotGrantedException
         * @throws PersistenceException
         */
        public Appartement getAppartement(int ref)  throws 
TransactionNotInProgressException, LockNotGrantedException, PersistenceException {
                try {
                        return (Appartement)db.load(Appartement.class, new 
Integer(ref));
                } catch (ObjectNotFoundException e) {
                        return null;
                }
        }
        
        /**
         * Acc�s � une cat�gorie de bien
         * @param nom nom de la cat�gorie
         * @return l'objet repr�sentant la cat�gorie
         * @throws TransactionNotInProgressException
         * @throws LockNotGrantedException
         * @throws PersistenceException
         */
        public Categorie getCategorie(String nom)  throws 
TransactionNotInProgressException, LockNotGrantedException, PersistenceException {
        try {
                return (Categorie)db.load(Categorie.class, nom);
        } catch (ObjectNotFoundException e) {
                return null;
        }
        }
        /**
         * Acc�s � la liste des cat�gories de biens
         * @return l'�num�ration des cat�gories
         * @throws Exception
         */
        public Enumeration getCategories() throws Exception {
                String oqlCategories = new String("SELECT c FROM interIMMO.Categorie 
c");
                oql= db.getOQLQuery(oqlCategories);
                return oql.execute();
        }
        /**
         * Effectue la recherche d�crite par l'objet recherche. Cette m�thode comporte 
pour l'instant
         * un certain nombre de limitations duent au fait que la recherche ne peut 
s'effectuer que sur 
         * les attributs des objets <i>Annonce</i> et <i>Bien</i>, les attributs des 
sous-types Habitation
         * Appartement et Terrain son innacessibles lors de la requ�te.
         * Les objets sous-types sont �galement innaccessibles durant une transaction 
comportant 
         * leurs sur-type. Par exemle si vous d�sirez suite � la recherche obtenir le 
d�tail d'un bien qui est une 
         * habitation vous devrez utiliser la m�thode <i>getHabitation</i> dans une 
autre transaction que celle 
         * qui a servi � ex�cuter la requ�te.  
         * @param re l'objet repr�sentant la recherche
         * @return une �num�ration des annonces r�pondant aux crit�res de <i>re</i>
         * @throws Exception
         */
        public Enumeration getAnnonces(Recherche re) throws Exception{
                int i=0;
                ArrayList param=new ArrayList();
                Collection c;
                StringBuffer oqlBiens=new StringBuffer("SELECT a FROM 
interIMMO.Annonce a WHERE");
                CodePostaux cpx=new CodePostaux("LoccArr.csv");
                
                //Cat�gorie
                //---------
                if(re.getCategorie()!=null) {
                        i++;
                        param.add(re.getCategorie());
                        oqlBiens.append(" Bien.Categorie = 
$"+Integer.toString(param.size()));                                          
                }
                
                //Disponibilit�
                //-------------
                if(re.getDate_disponibilite() != null) {
                        if(re.getDate_disponibilite().getAu_plus_tot()!=null){         
                 
                                if(i>0)
                                        oqlBiens.append(" AND ");
                                i++;
                                param.add(re.getDate_disponibilite().getAu_plus_tot());
                                oqlBiens.append( " Bien.date_de_disponibilite >= 
$"+Integer.toString(param.size()));                                                    
        
                        }
                        if(re.getDate_disponibilite().getAu_plus_tard()!=null){
                                if(i>0)
                                        oqlBiens.append(" AND ");
                                i++;
                                
param.add(re.getDate_disponibilite().getAu_plus_tard());
                                oqlBiens.append( " Bien.date_de_disponibilite <= 
$"+Integer.toString(param.size()));
                                                                        
                        }
                        
                }
                //Localisation
                //------------
                if(re.getLocalisation()!=null){
                        //Pays
                        //----
                        if(re.getLocalisation().getPays()!= null){
                                if(i>0)
                                        oqlBiens.append(" AND ");
                                i++;
                                param.add(re.getLocalisation().getPays());
                                oqlBiens.append(" Bien.pays = 
$"+Integer.toString(param.size()));
                        }
                        //Province
                        //--------
                        if(re.getLocalisation().getProvince()!=null){
                                if(i>0)
                                        oqlBiens.append(" AND ");       
                                i++;
                                oqlBiens.append(" Bien.code_postal IN list(");
                                
oqlBiens.append(cpx.getStringList(cpx.getCPforProvince(re.getLocalisation().getProvince())));
                                oqlBiens.append(")");
                        }
                        
                        //Arrondissement
                        //--------------                        
                        if(re.getLocalisation().getArrondissement()!=null){
                                if(i>0)
                                        oqlBiens.append(" AND ");
                                i++;
                                oqlBiens.append(" Bien.code_postal IN list(");
                                
oqlBiens.append(cpx.getStringList(cpx.getCPforProvince(re.getLocalisation().getArrondissement())));
                                oqlBiens.append(")");
                        }
                        
                        //Localit�
                        //--------
                        
                        if(re.getLocalisation().getLocalites()!=null){
                                Iterator locs= 
re.getLocalisation().getLocalites().iterator();
                                Localite loc;
                                boolean firstCP=true;
                        
                                if(locs.hasNext()) {
                                        if(i>0){
                                                oqlBiens.append(" AND ");
                                                i++;
                                        }
                                        oqlBiens.append(" Bien.code_postal IN list(");
                                        while(locs.hasNext()){
                                                loc=(Localite)locs.next();
                                                //Commune
                                                //-------
                                                if(loc.getCommune()!=null){
                                                        if(!firstCP)
                                                                oqlBiens.append(",");
                                                        
oqlBiens.append(cpx.getStringList(cpx.getCPforLocalite(loc.getCommune())));
                                                        firstCP=false;
                                                        
                                                }
                                                
                                                //Code postal
                                                //-----------
                                                if(loc.getCode_postal()!=null){
                                                        if(!firstCP)
                                                                oqlBiens.append(",");
                                                        oqlBiens.append("\""+ 
loc.getCode_postal() +"\"");
                                                        firstCP=false;
                                                }
                                        }
                                        oqlBiens.append(")");
                                }                               
                        }                                               
                }
                
                //Prix souhait�
                //-------------
                if(re.getPrix_souhaite()!=null){
                        
if(re.getPrix_souhaite().getValeur_minimale().floatValue()!=0){                        
 
                                if(i>0)
                                        oqlBiens.append(" AND ");
                                i++;
                                param.add(re.getPrix_souhaite().getValeur_minimale());
                                oqlBiens.append( " prix >= 
$"+Integer.toString(param.size()));                                                    
      
                        }
                        if(re.getPrix_souhaite().getValeur_maximale().floatValue()!=0){
                                if(i>0)
                                        oqlBiens.append(" AND ");
                                i++;
                                param.add(re.getPrix_souhaite().getValeur_maximale());
                                oqlBiens.append( " prix <= 
$"+Integer.toString(param.size()));
                                                                        
                        }
                }
                
                //Type d'annonce
                //--------------
                if(re.getType_annonce()!=null){
                        if(i>0)
                                oqlBiens.append(" AND ");
                        i++;
                        param.add(re.getType_annonce());
                        oqlBiens.append( " type = $"+Integer.toString(param.size()));
                }
                                
                //Execute la requ�te
                //------------------
                System.out.println(oqlBiens);
                oql=db.getOQLQuery(oqlBiens.toString());                
                Iterator j=param.iterator();
                while(j.hasNext()){
                        oql.bind(j.next());                     
                }
                return oql.execute();
                
        }
        
        /**
         * Insert l'objet dans la base de donn�e
         * @see interIMMO.DataAccess#getCurrentDatabase getCurrentDatabase
         * @param o Un objet dont la classe a �t� d�finie persistante
         * @throws ClassNotPersistenceCapableException
         * @throws DuplicateIdentityException
         * @throws TransactionNotInProgressException
         * @throws PersistenceException
         */
        public void create(Object o) throws ClassNotPersistenceCapableException, 
DuplicateIdentityException, TransactionNotInProgressException, PersistenceException {
                db.create(o);
        }
        
        /**
         * Supprime l'objet de la base de donn�e
         * @see interIMMO.DataAccess#getCurrentDatabase getCurrentDatabase 
         * @param o Un objet dont la classe a �t� d�finie persistante et qui a �t� 
pr�c�demment extrait de la base de donn�es
         * @throws ObjectNotPersistentException
         * @throws LockNotGrantedException
         * @throws TransactionNotInProgressException
         * @throws PersistenceException
         */
        public void remove(Object o) throws ObjectNotPersistentException, 
LockNotGrantedException, TransactionNotInProgressException, PersistenceException{
                db.remove(o);
        }
        
        /**
         * D�but d'une transaction
         * @see interIMMO.DataAccess#getCurrentDatabase getCurrentDatabase 
         * Equivalent � :<i>getCurrentDatabase().begin();</i>
         * @throws PersistenceException
         */
        public void begin () throws PersistenceException {
                db.begin();
        }
        
        /**
         * Fin d'une transaction et validation des modifications
         * @see interIMMO.DataAccess#getCurrentDatabase getCurrentDatabase
         * Equivalent � :<i>getCurrentDatabase().commit();</i>
         * @throws TransactionNotInProgressException
         * @throws TransactionAbortedException
         */
        public void commit() throws TransactionNotInProgressException, 
TransactionAbortedException {
                db.commit();
        }
        
        /**
         * Annulation des modifications et fin de la transaction
         * @see interIMMO.DataAccess#getCurrentDatabase getCurrentDatabase
         * Equivalent � :<i>getCurrentDatabase().rollback();</i>
         * @throws TransactionNotInProgressException
         */
        public void rollback() throws TransactionNotInProgressException {
                db.rollback();
        }
        
                                
}
----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to