Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
ManyToMany : how to save / find ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
CrYoSoRe  
View profile  
 More options Apr 16 2010, 6:23 am
From: CrYoSoRe <pellet.aurel...@gmail.com>
Date: Fri, 16 Apr 2010 03:23:03 -0700 (PDT)
Local: Fri, Apr 16 2010 6:23 am
Subject: [play-framework] ManyToMany : how to save / find ?
Hy.

I'm a newbie with JPA and i dont understand how can i use the
ManyToMany relation with Play  ?

Just see my code (in french i'm sorry):

/-------------------------------------------------------------------------- ---------/
package models;

import java.util.*;
import javax.persistence.*;

import play.db.jpa.*;

import models.FormatSiteWeb;
import models.MotCleSiteWeb;
import models.ThemeSiteWeb;

@Entity
/**
* Classe SiteWeb
* Classe utilisée pour stocker les différents site web references.
* @author a.pellet <pellet.aurel...@gmail.com>
* @see models.FormatSiteWeb;
* @since 2010/04/16
*/
public class SiteWeb extends Model {

        //
--------------------------------------------------------------------
        // Dependances avec les autres classes
        //
--------------------------------------------------------------------
        @ManyToOne
        public FormatSiteWeb formatDuSiteWeb;

        @ManyToMany
        public List<MotCleSiteWeb> listeDeMotsClesCorrespondantsAuSiteWeb;

        @ManyToOne
        public ThemeSiteWeb themeDuSiteWeb;

        //
--------------------------------------------------------------------
        // Proprietes de la classe.
        //
--------------------------------------------------------------------
                   public String nom;
        public String slogan;
        public String url;
        @Lob
        public String description;

        /**
        * Constructeur surcharge pour l'initialisation d'un site web.
        * @param String format
        * @param String nom
        * @param String slogan
        * @param String url
        * @param String description
        */
    public SiteWeb(FormatSiteWeb formatDuSiteWeb, ThemeSiteWeb
themeDuSiteWeb, String nom, String slogan, String url, String
description) {
                //
--------------------------------------------------------------------
                // Dependances avec les autres classes
                //
--------------------------------------------------------------------
                                      this.formatDuSiteWeb =
formatDuSiteWeb;
                this.listeDeMotsClesCorrespondantsAuSiteWeb = new
ArrayList<MotCleSiteWeb>();
                this.themeDuSiteWeb = themeDuSiteWeb;

                //
--------------------------------------------------------------------
                // Proprietes de la classe.
                //
--------------------------------------------------------------------
                this.nom = nom;
                this.slogan = slogan;
                this.url = url;
                this.description = description;
                this.nombreDePoint = nombreDePoint;

                   }

}

//------------------------------------------------------------------------- ----------------

package models;

import java.util.*;
import javax.persistence.*;

import play.db.jpa.*;

import models.SiteWeb;

@Entity
/**
* Classe MotsClesSiteWeb
* Classe utilisée pour stocker les différents mots clés des site web.
* @author a.pellet <pellet.aurel...@gmail.com>
* @see models.SiteWeb;
* @since 2010/04/15
*/
public class MotCleSiteWeb extends Model {

        //
--------------------------------------------------------------------
        // Dependances avec les autres classes
        //
--------------------------------------------------------------------
        @ManyToMany
        public List<SiteWeb> listeDeSiteWebCorrespondantsAuMotCle;

        //
--------------------------------------------------------------------
        // Proprietes de la classe.
        //
--------------------------------------------------------------------
                  public String nomDuMotCle;

        /**
        * Constructeur surcharge pour l'initialisation d'un mot cle.
        * @param String nom
        */
                   public MotCleSiteWeb(String nomDuMotCle) {
                //
--------------------------------------------------------------------
                // Dependances avec les autres classes
                //
--------------------------------------------------------------------
                this.listeDeSiteWebCorrespondantsAuMotCle = new
ArrayList<SiteWeb>();

                //
--------------------------------------------------------------------
                // Proprietes de la classe.
                //
--------------------------------------------------------------------
                                     this.nomDuMotCle = nomDuMotCle;
                   }

}

//------------------------------------------------------------------------- ---------------------

I have no probleme to save / find with ManyToOne or OneToMany but i
dont know how can i save / find on ManyToMany relation.

Someone have an exemple ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guillaume Bort  
View profile  
 More options Apr 16 2010, 2:27 pm
From: Guillaume Bort <guillaume.b...@gmail.com>
Date: Fri, 16 Apr 2010 20:27:23 +0200
Local: Fri, Apr 16 2010 2:27 pm
Subject: Re: [play-framework] ManyToMany : how to save / find ?
What is the problem exactly? Can you be more precise?

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dam74  
View profile  
 More options Apr 17 2010, 5:07 am
From: Dam74 <damienhur...@hotmail.com>
Date: Sat, 17 Apr 2010 02:07:28 -0700 (PDT)
Local: Sat, Apr 17 2010 5:07 am
Subject: [play-framework] Re: ManyToMany : how to save / find ?
When you map a same "ManyToMany relationShip" in both directions, you
need to tell which of these two directions is (kind of) the "master".
So : one of your @ManyToMany annotations must have the info :
"mappedBy" :

For example : if you have two entities : "Event" and "User", and a
User can "follow" several "Events",
and an Event can be followed by several Users ("ManyToMany
relationShip").

You would have :

in the entity User :
@ManyToMany(cascade=CascadeType.ALL)
    public Set<Event> followedEvents = new HashSet<Event>();

in the entity Event :
@ManyToMany(mappedBy="followedEvents")
    public Set<User> followsByUsers = new HashSet<User>();

A+ !

                       Dam74

On Apr 16, 12:23 pm, CrYoSoRe <pellet.aurel...@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
CrYoSoRe  
View profile  
 More options Apr 21 2010, 5:46 am
From: CrYoSoRe <pellet.aurel...@gmail.com>
Date: Wed, 21 Apr 2010 02:46:08 -0700 (PDT)
Local: Wed, Apr 21 2010 5:46 am
Subject: [play-framework] Re: ManyToMany : how to save / find ?
@Dam74

Thanks for your help !

@Guillaume Bort

I just have some difficulty to understand the ManyToMany relation :)
(And it's not easy to explain a problem when you dont understand the
subject)

Maybe because in a OneToMany or ManyToOne there is an explicit
"master" - "slave" dependency ?

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »