IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

[Hibernate]Lier 2 tables dans le hbm pour récuperer 2 objets


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Inscrit en
    Juillet 2002
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Juillet 2002
    Messages : 66
    Points : 53
    Points
    53
    Par défaut [Hibernate]Lier 2 tables dans le hbm pour récuperer 2 objets
    Bonjour,

    j'ai une table employee ainsi qu'une table login.

    un element de employee peut avoir 0 ou 1 element associé dans login.

    La table login possède 2 foreign key vers employee.

    J'aimerai lorsque je récupère un objet associé la table login, récupèrer en même temps l'objet associé de la table employee.

    J'ai donc dans mon objet login déclaré un objet de type employee.

    Maintenant il faut ajouter la définition de la liaison dans le fichier hbm de config mais la je bloque ...

    une idée ??

    Merci

  2. #2
    Membre régulier
    Inscrit en
    Octobre 2003
    Messages
    93
    Détails du profil
    Informations forums :
    Inscription : Octobre 2003
    Messages : 93
    Points : 86
    Points
    86
    Par défaut
    Sur quoi bloques tu ?

    Dans le fichier login.hbm, il te suffit de déclarer une relation de type one-to-one (ou many-to-one) vers la classe employe.

    one-to-one
    A one-to-one association to another persistent class is declared using a one-to-one element.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <one-to-one
    name="propertyName" (1)
    class="ClassName" (2)
    cascade="cascade_style" (3)
    constrained="true|false" (4)
    fetch="join|select" (5)
    property-ref="propertyNameFromAssociatedClass" (6)
    access="field|property|ClassName" (7)
    formula="any SQL expression" (8)
    lazy="true|proxy|false" (9)
    Hibernate 3.0.5 60
    entity-name="EntityName" (10)
    node="element-name|@attribute-name|element/@attribute|."
    embed-xml="true|false"
    foreign-key="foreign_key_name"
    />
    (1) name: The name of the property.
    (2) class (optional - defaults to the property type determined by reflection): The name of the associated
    class.
    (3) cascade (optional) specifies which operations should be cascaded from the parent object to the associated
    object.
    (4) constrained (optional) specifies that a foreign key constraint on the primary key of the mapped table references
    the table of the associated class. This option affects the order in which save() and delete() are
    cascaded, and determines whether the association may be proxied (it is also used by the schema export
    tool).
    (5) fetch (optional - defaults to select): Chooses between outer-join fetching or sequential select fetching.
    (6) property-ref: (optional) The name of a property of the associated class that is joined to the primary key
    of this class. If not specified, the primary key of the associated class is used.
    (7) access (optional - defaults to property): The strategy Hibernate should use for accessing the property
    value.
    (8) formula (optional): Almost all one to one associations map to the primary key of the owning entity. In the
    rare case that this is not the case, you may specify a some other column, columns or expression to join on
    using an SQL formula. (See org.hibernate.test.onetooneformula for an example.)
    (9) lazy (optional - defaults to proxy): By default, single point associations are proxied. lazy="true" specifies
    that the property should be fetched lazily when the instance variable is first accessed (requires
    build-time bytecode instrumentation). lazy="false" specifies that the association will always be eagerly
    fetched. Note that if constrained="false", proxying is impossible and Hibernate will eager fetch the association!
    Basic O/R Mapping

    Extrait de Hibernate Reference
    Va faire un tour sur le site hibernate.org et récupère le manuel de référence.

Discussions similaires

  1. Comment lier des tables dans access?
    Par allanibu dans le forum Bases de données
    Réponses: 5
    Dernier message: 01/10/2008, 15h35
  2. Réponses: 5
    Dernier message: 07/09/2006, 12h33
  3. Lier un table dans une base sécurisée ?
    Par marot_r dans le forum Access
    Réponses: 7
    Dernier message: 04/07/2006, 19h09
  4. Lier trois tables dans une seule requête ?
    Par tempirate dans le forum Requêtes
    Réponses: 2
    Dernier message: 18/06/2006, 19h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo