best way to handle DBs id's ?

Discussions

EJB design: best way to handle DBs id's ?

  1. best way to handle DBs id's ? (1 messages)

    Hi,
    i decided to model my db my database using auto_increment IDs for a few tables.
    I'm going through a design problem.
    Should ONLY my entities EJBs deal with tables ID's on methods or its acceptable to propagate the IDs to session beans and also let them work with the IDs?
    Suppose a method the needs to find a house in a db (the pk for the house table is houseid). Basically, i have two options:

    - retrieve the houseid in a Session EJB level and, then, getting the specific house
    - let the entity EJB work around to get the houseid and the specific house and then return only the house to the session level (in this case would my entity bean be dealling with some business logic?)

    Thanks,
    ltcmelo

    Threaded Messages (1)

  2. finder?[ Go to top ]

    If you want to find a house based on some other field than houseid I would put the finder code in SQL since SQL is much better at finding stuff in a relational DB than Java. Then create house objects from the result set and put them in a collection. It is ok to propagate the id to session bean but it should always be created in the persistence layer (at the same time as the house is created). The business layer probably need to have some ID concept to identify houses. I see no reason not to use the generated one.