Doubt User table and Friend table

Asked

Viewed 93 times

1

Eae guys, I need help, I’m a beginner in java, and I’m doing a college job where it’s going to be a mini social network, at the beginning we will make user registration, within the class Beans, user receives a listfriends I’m having a doubt.

my question, how I will relate this in the DAO and if I need to add some data in the table USUARIO_AMIGO with status etc ???

Can someone give me an example.

Tables in the USUARIO database and the other AMIGO_USUARIO.

             Tabela USUARIO

+-----------+------------------+----------+----------------+
| CD_LOGIN  | NOME_DE_USUARIO  |  SENHA   | EMAIL_USUARIO  |
+-----------+------------------+----------+----------------+
|       1   |      test        |   test   |       test     |
|       2   |      test        |   test   |       test     |
+---------+----------+----------+--------------------------+

              Tabela AMIGO_USUARIO

+-----------+---------------+-----------------+
| CD_AMIGO  | EMAIL_USUARIO | EMAIL_USUARIO2  |
+-----------+---------------+-----------------+
|       1   |      test     |      test       |    
|       2   |      test     |      test       |           
+---------+----------+----------+-------------+
  • Is using Hibernate?

  • this is a right framework? I can’t use any kind of framework, work rule :/

1 answer

0

You should have in the associative table, the status. And another important point, use user code and not email. If one day the user wants to change the email, you will have problems.

Tabela AMIGO_USUARIO

+-----------+---------------+-----------------+-------------+
| CD_AMIGO  | CD_USUARIO1   | CD_USUARIO2     |   status    |
+-----------+---------------+-----------------+-------------+
|       1   |      test     |      test       |    1        |
|       2   |      test     |      test       |    0        |
+-----------+---------------+-----------------+-------------+

In DAO you don’t relate the data, you just access it. You will have the relationship in Model, it will represent the bank entity in your application. Ex:

public class Amizade {
        public Amigo amigo1;
        public Amigo amigo2;
        int status;
    }
    // Essa abaixo é a DAO
    public class AmizadeRepository{
       public ArrayList<Amizade> fetchAll(){
        // fazer a consulta e retornar a lista
       }
    }
  • Thanks man for the tip, but you know how I would associate it in my DAO class? you have some example?

  • And I’m gonna need to create another membership table in the bank ?

  • Exactly, I edited the post to give you a better idea. The model is always a table in the database.

  • then I will need to create a friends class? , because until then I had called it within the user class. private Arraylist<Usuario> friends;

  • You can exchange Friend for User, it was just a name option.

  • yes, quiet, but you did the "Friendship", I would have to do another class? because I only made the User and the user does not receive the "status" only the table "usuario_amigo". not if you will understand

  • Friendship = user_friend and Friend = User. I only changed the nomenclature, but the concept is the same.

  • a understood, now a question that arose expensive, I will need to create a table in the bank to associate table friend + table user ?

  • type: User name

  • This table you have already created, is AMIGO_USUARIO. I don’t know if I confused you too much with the nomenclature change..

  • A little rs, sorry man I’m practically starting now

  • @Murilo Azevedo since he can’t use Ibernate, then the other "tool" is JPA?

  • Yeah, that’s right

  • jsp + Servlet + dao + bo so we are learning rs

Show 9 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.