Session vs Entity

I'm a first time java programmer and I'm going to program a webbased
application. I see everywhere the standard example of Enterprise Beans,
shoppingCart is a sessionBean, and userAccount is an EntityBean.
But how does the rest of the data interreact. In a bookstore for example, what are
all the available books in the database? Are they EntityBeans as well?
Seems logical, but what if there are thousands of books ? Doesn't this give
much overhead?

User account will be a session bean, since it will be specific to a client.
Bookmarks would be entity beans since they can be shared across multiple clients and persist across multiple invocations.
But a bookmark isn't really the same for all users. The url can be the same, but all the rest would be different. The name given to it, the last time it has been viewed by this user an thus also the fact that is has been changed or not since the last visit.
Also the user has to have a username and so forth, so isn't this an entity bean, much like the customer bean ?
Read this discussion to get a good assessment of JDO:I'll start by reading this, but expect more questions from me :-)
It's just that this is the first time I'm going to develop a J2EE application, and designing it from scratch isn't very easy then.

Similar Messages

  • How many ejbCreate() can be in Session and Entity Bean???

    Hi,
    How many ejbCreate() method can be in a Session and Entity
    Bean???
    How many can be in Stateless and Stateful SessionBean???
    How many can be in CMP and BMP SessionBean???
    Thanks,
    JavaCrazyLover

    How many ejbCreate() method can be in a Session
    ion and Entity
    Bean???For Stateful Session Beans and Entity Beans, as many as you'd like.
    Stateless Session beans can only have one, since their ejbCreate methods can not take any parameters.
    >
    >
    How many can be in CMP and BMP SessionBean???If you mean CMT/BMT(Container-Managed transactions / Bean-Managed Transactions), then
    the answer is the same. The create method requirements are independent of the transactional nature of the bean.
    If you really mean CMP/BMP(Container-Managed Persistence / Bean-Managed Persistence) , it doesn't apply to session beans, only entity beans. However, even for entity beans, CMP vs. BMP has no bearing on the rules regarding # of create methods.
    --ken
    >
    >
    Thanks,
    JavaCrazyLover

  • DBMS connection speed: Session vs Entity

    Environment: WLS6.1 SP3, W2K, Oracle 8.1.7, OCI Driver
    Hi,
    we are experiencing performance problem when getting a connection from a
    pool.
    Getting a connection from a stateless session bean takes 300-500ms whereas
    it takes 15ms
    from an entity bean (local). Both session and entity beans are deployed in
    the same ear.
    In both cases we're getting the datasource using the following code snippet
    Properties p = new Properties();
    bla bla bla ...
    Context ic = new InitialContext(p);
    DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/XXX");
    and
    DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/YYY");
    When getting the connection, we are experiencing the speed difference
    described above.
    connection conn = ds.getConnection();
    Why do we have this difference? We have the reference to the datasource
    already.
    There is no further JNDI lookup. Is there something we are missing?
    Thanks
    Arnaud
    Entity descriptor
    <resource-ref>
    <res-ref-name>jdbc/XXX</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Application</res-auth>
    </resource-ref>
    WLS specific
    <reference-descriptor>
    <resource-description>
    <res-ref-name>jdbc/XXX</res-ref-name>
    <jndi-name>jdbc/MyDataSource</jndi-name>
    </resource-description>
    </reference-descriptor>
    Session descriptor
    <resource-ref>
    <res-ref-name>jdbc/YYY</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Application</res-auth>
    </resource-ref>
    WLS specific
    <reference-descriptor>
    <resource-description>
    <res-ref-name>jdbc/YYY</res-ref-name>
    <jndi-name>jdbc/MyDataSource</jndi-name>
    </resource-description>
    <ejb-local-reference-description>
    <ejb-ref-name>ejb/XXX</ejb-ref-name>
    <jndi-name>ejb/XXXLocal</jndi-name>
    </ejb-local-reference-description>
    </reference-descriptor>

    Hi Arnaud,
    "Arnaud Benjacar" <[email protected]> wrote in message news:[email protected]...
    <JDBCConnectionPool DriverName="oracle.jdbc.driver.OracleDriver"
    InitialCapacity="5" MaxCapacity="10" Name="myPool"
    Properties="user=M594;password=M594;dll=ocijdbc8;protocol=oci8"
    Targets="ilimdev" URL="jdbc:oracle:oci8:@ilimdev"/>
    <JDBCTxDataSource JNDIName="jdbc/MyDataSource"
    Name="My Tx Data Source" PoolName="myPool" Targets="ilimdev"/>This configuration is far from the best performing one. I suggest you
    to change it to:
    <JDBCConnectionPool DriverName="oracle.jdbc.driver.OracleDriver"
    Properties="user=M594;password=M594;dll=ocijdbc8;protocol=oci8"
    InitialCapacity="20" MaxCapacity="20" Name="myPool"
    LoginDelaySeconds="1" RefreshMinutes="99999"
    ShrinkPeriodMinutes="5" ShrinkingEnabled="false"
    TestConnectionsOnReserve="true" TestConnectionsOnRelease="false"
    TestTableName="DUAL"
    Targets="ilimdev" URL="jdbc:oracle:oci8:@ilimdev"/>
    This configuration will perform better and will not spend time recreating
    connections and will require less synchronized operations inside the
    pool.
    BTW, in your code sample you look up two datasources. Are they bound
    to different pools?
    Regards,
    Slava Imeshev
    >
    >
    >
    "Slava Imeshev" <[email protected]> wrote in message
    news:[email protected]...
    Hi Arnaud,
    Could you post an extract from config.xml in part of the connection
    pools and datasources? I'm asking because the configuration
    you have may be not tailored to best performance.
    Regards,
    Slava Imeshev
    "Arnaud Benjacar" <[email protected]> wrote in message
    news:[email protected]...
    Environment: WLS6.1 SP3, W2K, Oracle 8.1.7, OCI Driver
    Hi,
    we are experiencing performance problem when getting a connection from a
    pool.
    Getting a connection from a stateless session bean takes 300-500mswhereas
    it takes 15ms
    from an entity bean (local). Both session and entity beans are deployedin
    the same ear.
    In both cases we're getting the datasource using the following codesnippet
    Properties p = new Properties();
    bla bla bla ...
    Context ic = new InitialContext(p);
    DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/XXX");
    and
    DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/YYY");
    When getting the connection, we are experiencing the speed difference
    described above.
    connection conn = ds.getConnection();
    Why do we have this difference? We have the reference to the datasource
    already.
    There is no further JNDI lookup. Is there something we are missing?
    Thanks
    Arnaud
    Entity descriptor
    <resource-ref>
    <res-ref-name>jdbc/XXX</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Application</res-auth>
    </resource-ref>
    WLS specific
    <reference-descriptor>
    <resource-description>
    <res-ref-name>jdbc/XXX</res-ref-name>
    <jndi-name>jdbc/MyDataSource</jndi-name>
    </resource-description>
    </reference-descriptor>
    Session descriptor
    <resource-ref>
    <res-ref-name>jdbc/YYY</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Application</res-auth>
    </resource-ref>
    WLS specific
    <reference-descriptor>
    <resource-description>
    <res-ref-name>jdbc/YYY</res-ref-name>
    <jndi-name>jdbc/MyDataSource</jndi-name>
    </resource-description>
    <ejb-local-reference-description>
    <ejb-ref-name>ejb/XXX</ejb-ref-name>
    <jndi-name>ejb/XXXLocal</jndi-name>
    </ejb-local-reference-description>
    </reference-descriptor>

  • Examples with JBeans / Session and Entity

    I wish if you could give links to web pages were to download examples of Java Beans
    using Session and Entity. In whole, JB that access relational databases.
    Best, would be an example to test and also that include the source code. Maybe
    an open source.
    Thanks for your directions,
    Janet

    Teox wrote:
    Thanks for your fast answering!
    Another thing: if I plan to use this way of developing my applications, could be a good idea putting my Session EJB with my business methods in session, instead of calling a new EJB and removing it each time I load a servlet?
    Thanks again.That depends on what you need to do. If you need to retain state between business method invocations (like a shopping cart) then store a Stateful Session bean in your http session. If you do not need to retain state then simply lookup a Stateless session bean each time you need it.
    m

  • Correct Principal not showing up in the Session and Entity EJB layer

    In our app a user is authenticated via the web container. The web layer then makes
    calls to various session EJB's.
    In our session bean, calls to sessionContext.getCallerPrincipal().getName() sometimes
    returns "SYSTEM" instead of
    the principal's name that was authenticated at the web container level.
    In our entity beans, calls to entityContext.getCallerPrincipal().getName()
    sometimes returns "<anonymous>" instead of the principal's
    name.
    A) Why isn't the principal's name = context's principal's name?
    B) Can we ensure that principal's name isn't lost?
    As per the documentation, the user principal is associated with the current thread,
    so why is it that when calls are made in the same thread of execution from the
    web layer to the EJB layer we are losing the right principal. Btw, the Principal
    is always correct in the Web layer. We do not have any RunAs options set in our
    EJB deployment descriptors.
    What are we doing wrong?

    You aren't doing anything wrong. This is a bug in the webservices.
    kapil khanna wrote:
    In our app a user is authenticated via the web container. The web layer then makes
    calls to various session EJB's.
    In our session bean, calls to sessionContext.getCallerPrincipal().getName() sometimes
    returns "SYSTEM" instead of
    the principal's name that was authenticated at the web container level.
    In our entity beans, calls to entityContext.getCallerPrincipal().getName()
    sometimes returns "<anonymous>" instead of the principal's
    name.
    A) Why isn't the principal's name = context's principal's name?
    B) Can we ensure that principal's name isn't lost?
    As per the documentation, the user principal is associated with the current thread,
    so why is it that when calls are made in the same thread of execution from the
    web layer to the EJB layer we are losing the right principal. Btw, the Principal
    is always correct in the Web layer. We do not have any RunAs options set in our
    EJB deployment descriptors.
    What are we doing wrong?

  • Session vs Entity Bean in Business Layer???

    Hi,
    I am developing a Hotel Management System project, I am planning to use the following softwares for it:-
    Presentation - JSP
    Web controller - Action class(Struts)
    Business Layer - Session Facade( Stateless Session Bean)
    DAO - Hibernate
    DB - Oracle 9i
    Model - ValueObject
    This is what i have decided to use to build the flow of the application.
    I have an idea about JSP,STRUTS,HIBERNATE & ORACLE. Since i have used it before.
    But in the case of business layer, i have doubt (since i am going to use EJB for the first time) whether to use a Session bean or entity bean where i will be writing my own queries(Stored proc.) as well as i will be using the predefined functions of hibernate to store the data .
    I also want to know whether i need to go for StatefullSB or Stateless SB if i use a sessionfacade(which i have planned to do)??
    When in what situation i need to for this approach???
    Please provide an answer for this & pls. do mention my flow is right or
    wrong??
    Excepting ur valuable thoughts..
    Thanks,
    JavaCrazyLover

    Hi
    I also want to know whether i need to go for StatefullSB or Stateless SB if i >use a sessionfacade(which i have planned to do)??
    When in what situation i need to for this approach???That depends on how your application will be used.
    Stateless and Statefull session bean are different.
    If you want to keep informations such as shopping cart, you can use Statefull.
    If you plan to have a huge number of request at time, Stateless can be faster.
    You can also keep your information such as shopping cart in the session scope of your web jsp tier. (if you use only web client.)
    In your case, i would choice, Stateless.
    Anybody, correct me if i'm wrong.
    Tks.

  • EJB - MDB and Session and Entity - Seem to always run under same Thread

    I am working on an application that implemets a connection from an MDB to a Session EJB which inturn connects to a Entity EJB. All connections are impemented as Local Home. I use log4j for tracing and notice that the thread ID reported for all activity is the same "Thread ID: MessageListenerThreadPool : 0" .
    This confuses me because I thought that all EJB's would execute under different threads. Have I done something wrong? Have I missinterpreted the EJB implementation? Any opinions would be greatly appreciated!!

    Hi Kelly,
    This is a slight misinterpretation of the EJB threading requirements. There are a couple different issues as play here. First, the main threading guarantee made by the spec is that a particular instance of an EJB will not be invoked by the container on more than one thread at a time. This is one of the guarantees that simplifies the EJB programming model so that developers don't have to do anything special (e.g. the use of synchronized blocks) to handle concurrent access. Second, the EJB Local programming model requires that invocations have pass-by-reference semantics. Of course, the easiest way for the container to provide that behavior is to literally make the local invocation on the same thread.
    The call-flow you're describing touches a single instance from three different beans, so the threading guarantee is not violated. Hope that clears things up a bit.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Choosing session vs. entity bean

    I am working on a web application that (among other things) needs to occasionally persist data in a database. I am using a DBUtil class that actually gets the DB connection and makes the update - all i do is pass it a string that represents the SQL statement. I want to create an EJB that can store a queue of statements (passed from the web classes) and periodically send them off to another EJB that will use the DBUtil class to do batch updates on the database.
    I need to determine which types of EJBs to use for the 2 beans. If the first bean (the one that queues up the SQL statements and periodically sends them along) is only going to be accessed by one client, should I just use a session bean? Or do I need to use an entity bean because the bean needs to 'sleep' between its periodic call to the other bean?
    The second bean simply waits to receive the set of SQL statements from the first bean and then passed them along to the DBUtil class for insertion into the DB. I was going to make this a session bean, but it seemed odd to have an entity bean calling a session bean (if the first bean should indeed be a entity bean). Are there any reasons why the second bean should be an entity bean instead of a session bean.
    Thanks.

    Hi,
    I think the design to use EJBs for implementing a kind of service which accumulates a set of db statements and then update the db does not call for the use of EJBs. This service could be implemented using simple java classes easily and then when a predefined threshold is reached, you can call the DBUtil class to update the db. In case you want to de-couple the task of updating the db then, on reaching the threshold post a message to a queue and then write a MDB which listens for this and it calls the DBUtil to do the update.
    If you want to run all your db statements in a context of a transaction, you can use a stateless session bean to call the DBUtil, but again the service has to be in a java class.
    Otherwise I dont see the use of EJBs, especially two beans one calling the other as stated by you as a good design.
    Regards,
    Naveen

  • Getting session from entity

    When a button is pressed on a login screen, am doing this.
    EL.set("#{sessionScope.userID}", <name> );
    Also tried
    request.getSession().setAttribute("userID", <name> );
    At some point, in a method inside an entityImpl override, am doing this.
    private String getCurrentUser() {
    SessionImpl sess = (SessionImpl) getDBTransaction().getSession();
    String userName = (String) sess.getUserData().get("userID");
    System.out.println("Username is " + userName);
    return userName;
    I am seeing "Username is null".
    How do I retrieve the session userID from within an entity?
    Thanks
    Ed Schechter

    Hi,
    its not the web session you are dealing with in ADF BC. SRDemo uses a VO that holds the authenticated user information and uses a bind variable to get the username (the email) from the web application. If you set jbo.security.enforce to 'Must' then the username is accessible from the ApplicationModuleImpl file as getUserPrincipal(). However, in this case the user needs to be authenticated before ADF BC is instantiated.
    Frank

  • [HOWTO] JSF + Session Facade + Entity Bean (EJB3)

    I'm trying to find a tutorial that shows the advisable way to use JSF with EJB 3 entity beans using the Session Facade pattern (?), but the only tutorials around show very basic usage of JSF (validation, conversions etc.).
    The only thing that is close is this: http://forum.java.sun.com/thread.jspa?threadID=5122284 but still not what I'm looking for.
    Is there any documentation available out there..?
    Message was edited by:
    HakelRausd

    Hi,
    I updated the online doc in blueprints solutions catalog with a small explanation of using JSF with EJB Session Bean at https://blueprints.dev.java.net/bpcatalog/ee5/persistence/ejbfacade.html
    I will add an image soon too. The basic idea for JSF and EJB3 programming model is
    JSF Page --> JSF Managed Bean(backing bean) --> Session Bean --> Java Persistence Object.
    In general, ther would be several JSF pages,and several JSF Managed Beans, and several Java Persistence Objects, but fewer Session Beans. The Session Bean would be expected to be shared and accessed by several managed beans with with Session Bean serving as a facade to the Java Persistence Objects, so there would be few Session Beans.
    The Session Bean would usually be a local Session bean and would only be remote if-and-only-if you wanted RMI-IIOP access. Usually web components like Servlets and JSF Managed Beans use local access to the Session Beans and the access is within the same VM, no remoteness.
    Most of the time, the Session Bean would be a Stateless Session Bean, and would not be a Stateful Session Bean.
    hth,
    Sean

  • Multi session over Entity bean

    Hi All,
    How an Entiry bean will be persistent over multi sessions.
    Any help will be appreciated

    Entiies are backed by some sort of database. What exactly do you mean by "multi sessions?"

  • Internal error:Ag Store Provider Session:get entity by id:id must be number or string

    Hi getting this error message when moving a group of dng images from lrm5 for editing in elements 12.Works fine if only moving a single image?

    Start with the steps here:
    Troubleshoot unexpected behavior | User account-specific | Adobe software | Windows 7, Vista
    http://helpx.adobe.com/x-productkb/global/troubleshoot-unexpected-behavior-user-account-2. html

  • Paradox - Should entity CMP EJB be faster than stateless session bean?

    Please bear with me on this.
    Just thinking of this scenario: hello world application. It can be implemented both as stateless session bean and entity bean.
    There's no persistent. So for the entity bean, it will be container managed, and no code to do anything to the load/remove/create. - comparably the same as stateless bean.
    Next, for the stateless session bean, each client call would require a dedicated instance of the EJB on the server (although for a very short amount of time). For the entity bean, it's shared, so only 1 instance is needed. It's also thread safe.
    So, for a very high traffic, shouldn't the entity bean do better because of single instance?
    What's other overhead?
    Does the entity bean cost more connections than the stateless bean?

    Feels like a comparison between apples and oranges.
    A stateless session bean is like every other instance, so these can be pooled by the EJB container. The container is free to create an instance for each client if necessary. That's different.
    A stateless session bean doesn't have to deal with a database that may or may not be located on another machine the way an entity bean does. There could be another network round trip involved. That's different.
    Session and entity beans are intended for entirely different purposes. Just because you can write Hello World with both doesn't mean it's representative of what EJBs are used for. I don't think it's a good, meaninful comparison. JMO - MOD

  • Creating a Session & Entity bean in Weblogic

    Hii javaities
    I am new 2 EJB , and i want 2 create a apllication using EJB.
    I want 2 create a session , and entity bean in WEblogic.
    Can anybody help me i this
    Or if u have some good links , plz pass it 2 me.
    Thanking in anticipation

    http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.html
    http://www.oracle.com/technology/sample_code/tech/java/j2ee/designpattern/businesstier/sessionfacade/readme.html
    google search for more.

  • Problem with getting Entity Beans refreshed within Session bean methods

    I hav following code in session and entity beans:
    Session bean pseudo code: (PrimaryKey is primary key class for the entity
    bean referred here, and MySessionHome is the home interfac class for this
    session bean).
    public class MySession implements SessionBean {
    // This method is present in remote interface class as well.
    public void methodA(PrimaryKey pk) {
    // code to find entity bean by primary key specified.
    update the entity bean, and mark it as isModified.
    public void methodB(PrimaryKey pk) {
    // code to find entity bean by primary key specified.
    do something.
    public void methodC() {
    MySessionHome sessHome = code to lookup sessionhome from JNDI.
    MySessionRI sess = sessHome.create(); // MySessionRI is the remote
    interface class for MySession
    PrimaryKey pk = new PrimaryKey(params);
    sess.methodA(); // LINE ABC1
    sess.methodB(); // LINE ABC2
    all the entity and session bean methods have required as the TX attribute.
    In methodB() on LINE ABC2, the entity bean obtained by findByPrimaryKey does
    not reflect the changes made in call to methodA() on LINE ABC1.
    Now if I change the LINE ABC1 and LINE ABC2 to
    methodA(); // LINE ABC1
    methodB(); // LINE ABC2
    in this case the entity bean obtained in methodB() has the changes made in
    methodA().
    Any idea why this is happening?

    Hi ad13217 and thanks for reply.
    I'm sorry but my code is like this:
    javax.naming.Context ctx=new javax.naming.InitialContext();
    arguments was an error on copy, but it doesn't work.
    Thanks
    Fil

Maybe you are looking for

  • Two message in different files widout help of UTL_FILE

    Hi All..happy new year in advance..! I am in a strange scenerio by my client.I am having below type of code in which I am writing log via "dbms_output.put_line" but he needs that whenevr any error came into code eror message should be written in sepa

  • Deposit invoices and payemnts from Order Manangment

    Hi All, We manually create Deposit invoices in AR then generate the Receipt and manually apply these receipt to Deposit invoices. Accountant generally complete this activity while booking the order. The goods are delivered to customers based on sched

  • How to find this count...

    Hi all, I have two tables like this. desc tp030_actl_mstr  Name                         Type                                                                                                                         PLN_YEAR_Y                 NUMBER(4) 

  • Iphone will not let me select music via genres in itunes

    hello forum. can anyone pls tell me how to make the ipod on my iphone choose music from my genres. in itunes i can select music via genres but when i sync to my iphone the genre button always displays that there is no music in that particular genre e

  • How can I shutdown the external application?

    Hi I excuted an external application with "Runtime.getRuntime.exec". How can I shutdown the external applicaiton(calc.exe..) which is called by me? Younghwan