EJB + DAO

Hi form
I have read the Java Blue Prints and was confused with the DAO Objects in EJB.
Can some body on the form Explain me How to Write a DAO for Entity
or at least spare me some code where I can look up to.
Plz do not have any URL's
With regards
Karthik

I would also like to know if it's possible to have
ve a session bean thread to start running for
<LOAD -ON-STARTUP> of the J2ee Container,
[ similar to the ones instandalone  webcontainer as
TOMCAT]Application servers have a facility to use custom startup classes. You could write one which would invoke your session bean.
http://e-docs.bea.com/wls/docs81/ConsoleHelp/startup_shutdown.html
If you would elaborate more on your requirement, someone might know a better solution.

Similar Messages

  • EJB, DAO, DTO Advise need please

    Hello all,
    This is for java j2ee experts. I have been reading lots of books with regard to java patterns. I understand how DAO but not completely understand how DTO�s are works. It seems we use DTO�s to transfer data between business object to DAO and business object to client. As my understand DTO�s should have all the get and set method so client can directly manipulate the local data.
    My confusion is if DTO� has all the get and set methods and clients can directly minupulate it; what else left there to put as business methods into EJB other than insert, update, and delete?
    For example,
    Let assume I have DTO call SalesOrderDTO, which has complete record of sales order and all the get and set methods to access it properties. My SalesOrderEJB (session bean) create the DTO, SalesOrderDAO creates the SalesOrderDTO and passed to the Bean, based on client request and pass the SalesOrder DTO to requesting client. And client uses get and set method to manipulate SalesOrderDTO and send it back to SalesOrderEJB to update, insert or delete it. So in this case what else I should put into SalesOrderEJB? Most books only talk about delete(), insert(), get(), get data from database, update() as business methods. I thought business methods should be more than inset(), get(), update() like data validation, and data conditions. In this case it is safe to allow client manipulate the DTO?
    Can someone expand this example and explain little bit more about business methods? I appreciate any explanations from experts.
    Thanks
    AP

    You are mixing up the Entity bean and session bean layers.
    Entity beans primarily act as an interface against a datasource. Thats why they have only those methods such as update(), insert(), delete()...And unless you have serious enough reason not to do so stick with it.
    Session beans is the layer where you would have your business methods..
    I cant think of a reasonable scenario for your SalesOrder, but in other cases such as making a money transfer from a bank account, several transactions or business operations have to be perfomed. This is usually done in the sesion bean layer.

  • Update form another EJB with DAO persistence

    We have two modules with EJB Session, stateless, with CMT requeried in all methods, the first module has the persistence tier wiht DAOs pattern and the other module uses TopLink. We are using JSF as framework in the presentation layer, when we are going to update the database from web form a backing bean JSFcalls the first EJB (DAOs persistence) and this EJB invokes the other EJB (Toplink persistence). and throws the next exception
    05/10/31 17:12:12 java.lang.NullPointerException
    05/10/31 17:12:12      at oracle.toplink.internal.indirection.UnitOfWorkValueHolder.getValueFromServerObject(UnitOfWorkValueHolder.java:105)
    05/10/31 17:12:12      at oracle.toplink.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:144)
    05/10/31 17:12:12      at oracle.toplink.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:64)
    05/10/31 17:12:12      at oracle.toplink.internal.indirection.BasicIndirectionPolicy.cloneAttribute(BasicIndirectionPolicy.java:88)
    05/10/31 17:12:12      at oracle.toplink.mappings.ForeignReferenceMapping.buildClone(ForeignReferenceMapping.java)
    05/10/31 17:12:12      at oracle.toplink.internal.descriptors.ObjectBuilder.populateAttributesForClone(ObjectBuilder.java:1492)
    05/10/31 17:12:12      at oracle.toplink.publicinterface.UnitOfWork.cloneAndRegisterNewObject(UnitOfWork.java:601)
    05/10/31 17:12:12      at oracle.toplink.publicinterface.UnitOfWork.internalRegisterObject(UnitOfWork.java:2294)
    05/10/31 17:12:12      at oracle.toplink.internal.sessions.MergeManager.registerObjectForMergeCloneIntoWorkingCopy(MergeManager.java:688)
    05/10/31 17:12:12      at oracle.toplink.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:397)
    05/10/31 17:12:12      at oracle.toplink.internal.sessions.MergeManager.mergeChanges(MergeManager.java:181)
    05/10/31 17:12:12      at oracle.toplink.publicinterface.UnitOfWork.mergeClone(UnitOfWork.java:2634)
    05/10/31 17:12:12      at oracle.toplink.publicinterface.UnitOfWork.deepMergeClone(UnitOfWork.java:1231)
    05/10/31 17:12:12      at siscoi.declaracionescambio.business.DeclaracionesCambioMngr.grabarDeclaracionCambio(DeclaracionesCambioMngr.java:222)
    when the objects are new the TopLink framework works good, but when the object already exist in the DB, does not make the update an thorw the null pointer exception why?.
    We implements a Client Class to only test the EJB with Toplink persistence. In this class read a object from de database and i modify the object and calls the update method and the update works good.
    Container oc4j 10.1.2
    Toplink 9.0.4
    jdk 1.4.2.04
    please help me!!

    It looks like the issue is occurring because the object that you are merging is a new object, or TopLink thinks it is a new object and it is being registered as a new object. The new object has a non-instantiated value-holder that seems to have been serialized so can no longer be instantiated, but the relationship is required to persist the new object.
    My guess is that the object is not new, but existing, and the issue is most likely with your does-exist-check option. The original object may no longer be in the cache, so you most likely need to use check-database for your descriptor's does-exist option, instead of the default of check-cache.

  • Writing to BLOB with getBinaryOutputStream

    I'm trying to insert a BLOB and have problems with a variety of the methods listed in documentation.
    1) The method that is in the Oracle examples, oracle.sql.BLOB.getBinaryOutputStream(), give me a warning that it is deprecated.
    2) In other Oracle documentation, getBinaryOutputStream(long) is specified, but that doesn't exist in my version of oracle.sql.BLOB.
    3) Yet other documentation says to use the JDBC 3.0 standard call, which is setBinaryStream(long). However, I get this error when running it: java.lang.AbstractMethodError: java.io.OutputStream oracle.sql.BLOB.setBinaryStream(long)
    I don't want to use the deprecated method, but that's the only one that works. Any ideas?
    Using 10g driver with an 8i database.
    thanks

    I’m not sure how to use PreparedStatement.setBlob(Blob). Seems like the only way to create a BLOB is to SELECT it, and then you still need to call BLOB.setXXX. I tried setBytes(..) but get the same AbstractMethodError as with setBinaryStream(..)
    Here’s the stacktrace from JDev, not sure it has what you're looking for. In this scenario, I use a PreparedStatement to create a blob locator using this:
    String CREATE_STATEMENT = "INSERT INTO IWR_FILE " +
    "(SA_FILE, SA_IWR, FILE_NAME, FILE_BLOB) VALUES " +
    "( ?, ?, ?, empty_blob())";
    I then select that record and try to write the blob using:
    (imported oracle.sql.BLOB)
    ResultSet blobRS = blobPS.executeQuery();
    BLOB blob = (BLOB) blobRS.getBlob(1);
    OutputStream blobOUT = blob.setBinaryStream(1L);
    Tried casting the ResultSet to an OracleResultSet, but still got the error.
    com.evermind.server.rmi.OrionRemoteException: Transaction was rolled back: java.lang.AbstractMethodError: java.io.OutputStream oracle.sql.BLOB.setBinaryStream(long)      at IWRFacade_StatelessSessionBeanWrapper0.setDTOList(IWRFacade_StatelessSessionBeanWrapper0.java:621)      at iwr.ejb.beans.Tester.testFileDAO(Tester.java:117)      at iwr.ejb.beans.Tester.main(Tester.java:47)      at mypackage7.InitiatorServlet.init(InitiatorServlet.java:27)      at com.evermind.server.http.HttpApplication.loadServlet(HttpApplication.java:2094)      at com.evermind.server.http.HttpApplication.findServlet(HttpApplication.java:4523)      at com.evermind.server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2413) 04/08/30 09:49:04 com.evermind.server.rmi.OrionRemoteException: Transaction was rolled back: java.lang.AbstractMethodError: java.io.OutputStream oracle.sql.BLOB.setBinaryStream(long); nested exception is:
         java.rmi.RemoteException: java.io.OutputStream oracle.sql.BLOB.setBinaryStream(long); nested exception is:
         java.lang.AbstractMethodError: java.io.OutputStream oracle.sql.BLOB.setBinaryStream(long)      at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:640)      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)      at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)      at java.lang.Thread.run(Thread.java:534)      Nested exception is: java.rmi.RemoteException: java.io.OutputStream oracle.sql.BLOB.setBinaryStream(long); nested exception is:
         java.lang.AbstractMethodError: java.io.OutputStream oracle.sql.BLOB.setBinaryStream(long)      at com.evermind.server.ejb.EJBUtils.makeException(EJBUtils.java:941)      at IWRFacade_StatelessSessionBeanWrapper0.setDTOList(IWRFacade_StatelessSessionBeanWrapper0.java:621)      at iwr.ejb.beans.Tester.testFileDAO(Tester.java:117)      at iwr.ejb.beans.Tester.main(Tester.java:47)      at mypackage7.InitiatorServlet.init(InitiatorServlet.java:27)      at com.evermind.server.http.HttpApplication.loadServlet(HttpApplication.java:2094)      at com.evermind.server.http.HttpApplication.findServlet(HttpApplication.java:4523)      at com.evermind.server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2413)      at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:640)      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)      at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)      at java.lang.Thread.run(Thread.java:534) Caused by: java.lang.AbstractMethodError: java.io.OutputStream oracle.sql.BLOB.setBinaryStream(long)      at iwr.ejb.dao.FileDAO.getInsertPS(FileDAO.java:244)      at iwr.ejb.dao.FileDAO.setDTO(FileDAO.java:90)      at iwr.ejb.beans.IWRFacadeBean.setDTOList(IWRFacadeBean.java:102)      at IWRFacade_StatelessSessionBeanWrapper0.setDTOList(IWRFacade_StatelessSessionBeanWrapper0.java:564)      ... 11 more

  • WSAD : loading properties file from EBJ project

    Hi,
    I am trying to load properties file contains database parameters into my EJB project. I am using WSAD as IDE tool
    can you please help me with following.
    1. where to place the .properties file physically ?
    2.how to load the file to my EJB/DAO classes
    3.can i use the same location to place log4j.properties file as well ?
    I have tried doing in different ways but none is working.
    thank you
    Narendra

    got it working , for information pl go to the following page and section "Using log4j in an EJB Application"
    i have followd same steps for loading my properties file .
    http://sys-con.com/story/?storyid=43413&DE=1

  • Newbie: is JSP thread safe?

    New to JSP and trying to understand the thread-safe-code thing.
    An example maybe is the best way to ask (Tomcat 4 and Win2000/IIS, MsSQL2000, MsJDBC)
    I have a mypage.jsp page which uses a bean (mybean.class) to fill up the page from a database and also make updates to the database. So the bean has connect,disconnect,query by returning resultsets, all the database stuff.
    The question: suppose two users get to the page at the same time and press the update button at the same time, what happens?
    user1 -> mypage.jsp -> mybean.class
    user2 -> mypage.jsp -> mybean.class
    So does the mypage.jsp or mybean.class run in tomcat for both users as one copy? Can user1 database update mix up with user2 database update? And if yes, how can i prevent that? Or am I totally lost..
    -- Mixed up newbie --

    Hi,
    What we are talking about here is Transaction not Threading.
    To separate view with business and data access, it's the business class model that take care about it and not the view (JSP pages).
    So here's what to do in a serious world :
    JSP --> class that support JTA (it may be a simple class or an EJB) --> DAO class.
    Hope it's clear enough

  • Throw sqlexception: broken pipe when executing sql or other related code

    My env is:
    weblogic 704 + oracle 8i, use datasource to create conneciton pool with 10 connections
    when weblogic starts, but when I execute some sql , the system throwed out:
    java.sql.SQLException: Io Exception: Broken pipe
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
    at oracle.jdbc.driver.OracleStatement.open(OracleStatement.java:560)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2778)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:536)
    at weblogic.jdbc.pool.PreparedStatement.executeQuery(PreparedStatement.java:53)
    at com.ztsoft.ejb.dao.EntityDAO.readClobToFile(Unknown Source)
    at com.ztsoft.ejb.dao.SL_FileContentTbDAO.readClob2(Unknown Source)
    at com.ztsoft.ejb.sessionbean.MainHandlerBean.readClobToFile(Unknown Source)
    at com.ztsoft.ejb.sessionbean.MainHandlerBean_oejxo1_ELOImpl.readClobToFile(MainHandlerBean_oejxo1_ELOImpl.java:531)
    at com.ztsoft.web.servlet.GetResultActionServlet.service(Unknown Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1075)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:418)
    How can I solve ? thanks, this is very urgent, help me..

    CottonXu wrote:
    My env is:
    weblogic 704 + oracle 8i, use datasource to create conneciton pool with 10 connections
    when weblogic starts, but when I execute some sql , the system throwed out:
    java.sql.SQLException: Io Exception: Broken pipe
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)Hi. This indicates a problem between the oracle driver version and the DBMS
    version. The first thing to do is to go to oracle's download site and get
    their latest version of the thin driver that is appropriate for your DBMS
    and JVM, and then edit your startWeblogic script so the new driver is ahead
    of the weblogic.jar in the -classpath argument for the commandline that
    starts the server.
    Joe
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
    at oracle.jdbc.driver.OracleStatement.open(OracleStatement.java:560)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2778)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:536)
    at weblogic.jdbc.pool.PreparedStatement.executeQuery(PreparedStatement.java:53)
    at com.ztsoft.ejb.dao.EntityDAO.readClobToFile(Unknown Source)
    at com.ztsoft.ejb.dao.SL_FileContentTbDAO.readClob2(Unknown Source)
    at com.ztsoft.ejb.sessionbean.MainHandlerBean.readClobToFile(Unknown Source)
    at com.ztsoft.ejb.sessionbean.MainHandlerBean_oejxo1_ELOImpl.readClobToFile(MainHandlerBean_oejxo1_ELOImpl.java:531)
    at com.ztsoft.web.servlet.GetResultActionServlet.service(Unknown Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1075)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:418)
    How can I solve ? thanks, this is very urgent, help me..

  • Analysis diagram

    I have a problem which will eventually be solved using ejbs and servlets but have been asked to produce an analysis class diagram without mentioning servlets, ejbs and databases.
    The application is an online bank, the diagram should not mention any technologies, what sort of things should I include and how should I present it?
    Many thanks

    I have a problem which will eventually be solved using
    ejbs and servlets but have been asked to produce an
    analysis class diagram without mentioning servlets,
    ejbs and databases.
    The application is an online bank, the diagram should
    not mention any technologies, what sort of things
    should I include and how should I present it?
    ejbs => DAO http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
    You just need one per entity.
    database => data model. You refer to storage in terms of a "persistent store" (any place you feel the urge to put "database" put "persistent store" instead.)
    Servlets => Session Facade http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.html
    (However poke around something else in the bottom layer might fit a little better.)
    Keep in mind that the above are patterns and do not tie you to an implemention (including implimenting it in java.)

  • EJB classpath problem when refering a DAO in library jar file

    Hi
    When I tried to deploy an EJB jar file in 10g which references the DAO for getting database[SQL Server2000] query results.Its not retriving data nor throwing any exceptions.Other DAO business methods which do not access database are working well.
    When I tried to import the DAO inside a JSP and calling the DAO data access method which is working fine. Even I have set the resource-ref [datasource JNDI Name] in ejb-jar.xml files for the EJB beans, but its not referencing. If you have any ideas, how to resolve this problem, please forward me your suggestion.
    Thanks in Advance
    Best Regards
    Venugopal Balu

    Hi
    When I tried to deploy an EJB jar file in 10g which references the DAO for getting database[SQL Server2000] query results.Its not retriving data nor throwing any exceptions.Other DAO business methods which do not access database are working well.
    When I tried to import the DAO inside a JSP and calling the DAO data access method which is working fine. Even I have set the resource-ref [datasource JNDI Name] in ejb-jar.xml files for the EJB beans, but its not referencing. If you have any ideas, how to resolve this problem, please forward me your suggestion.
    Thanks in Advance
    Best Regards
    Venugopal Balu

  • Can I Use Singletone  Pattren for DAO in Stateless EJB?

    Hi friends,
    I have a design in which i am creating an Business Layer using EJB (Stateless). In my case i have only read only to DataBase and at one case where i will be updating the database. But my application will be accessed by many concurrent users.
    My problem is if i create a DAO with singleton pattren then it will be returning the same instance to all the person who access the DB. So if one person is reading the database and at the same moment one more person request for update since the DAO is singleton object will there be any conflict?
    Reply soon

    Hi Martin.S
    Thanks for your suggestion.
    U Asked
    You need to think about why have you have made your DAO a Singleton. You need to ask yourself, SHOULD it be a Singleton? It may be valid decision but I find that doubtful. Singleton DAO's suit only limited set of circumstances. Why i decided to use singleton pattren was :
    Since i am using session bean and if i won't use Singleton pattren and
    If my app was used by say 1000 users
    Then 1000 Dao instaces whould be created!
    The App Server will have 1000 refrences which may be a performance issue and may slow down the server due to more usage of server resource. So i need to know weather is it a good idea to use the Singleton pattren for DAO when using SessionBeans?
    And one more doubt I have Martin
    If i use One Dao Class Per One Table Then How about the factories if i use singleton? Need to create so many factories as DAO's? *reply
    Also i think if i use Single DAO per Table and if i have say 1 user accessing the DAO and he is in the Middle of his execution and user 2 requests for the same DAO once again the situation is worse! Am i right?
    So I think Singleton pattren comes into handy only when one person is accessing the DAO at a time. After he completes then only we can give access to some one else.
    And also while Using EJB's Using syncronized DAO is not preffered since EJB's are for multiple access
    So do you have any solution for the same? Currently I am using ordinary DAO and creating multiple instances in the Session Bean.
    Is there any way to Use SingleTon Pattren inside SessionBean?
    Reply
    A Singleton DAO would be valid choice when you are doing performance/throughput optimisation for read only access to dataset which you have cached for speed, but need to ensure only one copy exists for memory efficiency.One more query martin,
    How can we use it for read only access to a data set?
    For example i have a DAO which queries and returns some result sets based on some input value given by the user
    Now take a senario1: User1 supplys some input value and executes method1() and he is in the middle.
    User2 comes in and acess the same method1() with different input value
    Since it is a SingleTon Pattren The User2 will get same refrence
    So user1 will get the result set that is having the input parameters of user2. Right?????????
    So my inference is we cannot use singelton pattren for concurrent acess of the DAO.What do you say
    Please Reply Martin

  • Bmp entity ejb transactions, using DAO objects

    hi all,
    i'm new to entity ejb's... i'm using the j2ee reference implementation (1.3.1) with the cloudscape db to test my code.
    i can't seem to get my ejbCreate method to work. i'm using a DAO object to encapsulate all my database code, and simply call dao.insert(...) in my ejbCreate method.
    i tested the dao object, and it works fine when it's invoked straight. but when i try to invoke under the ejb container i run into problems:
    i deploy the bean with container managed transactions:
    (1) with the 'required' attribute:
    I get a javax.transaction.RollbackException nested inside another RollbackException, nested inside a RemoteException, nested inside another RemoteException. The final RollbackException says <<no stack trace available>>...
    So I've got no clue what's causing it...
    (2) with the 'never' attribute:
    I get a NullPointerException nested inside another NullPointerException, nested inside a RemoteException, nested inside another RemoteException. The final NullPointerException says <<no stack trace available>>...
    So I've got no clue what's causing it...
    I'm assuming something messed up with my deployment -- but I've checked it against all the examples I can find -- seems to be correct. Would the encapsulated Data Access code cause a problem? Some other config problem?
    Thanks in advance for any help!!

    i'm using the cloudscape db that's already configured with the server. i believe the datasource is correctly configured, as i am able to successfully invoke the dao methods straight -- the problem occurs when I try to do it via the entity bean that uses the dao object.
    here's my server startup messages:
    Binding DataSource, name = jdbc/Cloudscape, url = jdbc:cloudscape:rmi:CloudscapeDB;create=
    true
    Binding DataSource, name = jdbc/DB1, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
    Binding DataSource, name = jdbc/EstoreDB, url = jdbc:cloudscape:rmi:CloudscapeDB;create=tr
    ue
    Binding DataSource, name = jdbc/InventoryDB, url = jdbc:cloudscape:rmi:CloudscapeDB;create
    =true
    Binding DataSource, name = jdbc/DB2, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
    Binding DataSource, name = jdbc/XACloudscape, url = jdbc/XACloudscape__xa
    Binding DataSource, name = jdbc/XACloudscape__xa, dataSource = COM.cloudscape.core.RemoteX

  • JPA EJB generic DAO

    I am using Jdeveloper 11g R (11.1.2.3) & weblogic 10 G
    In my pages I use JSF & Facelet
    Hi All
      In a new project I am going to use JPA / EJB session beans and ADF Faces
      Also I am going to use similar pattern described in below link for a GenericDAO
      and inject instances of Generic EJB into my business EJBs
        http://www.adam-bien.com/roller/abien/entry/generic_crud_service_aka_dao
        https://blogs.oracle.com/theaquarium/entry/generic_jpa_dao_repository_implementation
      In second link some people mentioned this way is old and over simplified
      Any body have any comment / ideas or similar cases
      I don't want use any external open source libraries
    Thanks
    Mohsen

    I've read that article several months ago and didn't get a chance to try it out. However, I did work with Hibernate quite a bit.
    I believe the author would have us replace this:
    public update(Person person){
    with this:
    public void update(T o) {
    In the first function, its obvious that I'm updating a record in the Person table.
    In the second function, I need to have a list of all the possible table names (such as 'Person') to know which tables have an update function associated with it that I can use with the generic function. For example, some tables may be read-only and dont have an update function.
    Normally, the compiler helps you out by providing a dropdown list of functions an object has that you can choose from.
    Likewise, the compiler will have a dropdown list of all the different arguments (signatures) a function has.
    I dont think the generic function will provide this. As an end-user calling up a Hibernate function that you wrote, I want help from the compiler on what my options are. I don't want to dig into the Hibernate configuration file to determine weather update is allowed for a table or not.
    The downside of not using generics of course, is you have to write a DAO with CRUD functions for each and every table in the database (actually, for every graph, but lets not get into that).
    Also, I don't see an example of how the associations between tables is implemented in generics. For example, one to many relationships, etc. A developer may get bogged down trying to get generics to work for all those possiblies (then again, perhaps not, since I didn't try it).
    By the way, I don't see anything about generic DAO on the internet younger than 2 years old so I suspect it hasn't caught on.

  • Where to Instantiate a DAO in an EJB BMP?

    We are using DAOs with our EJB BMPs..
    My question is what method should the DAO be Instantiated in?
    I have seen it done in the:
    1) ejbActivate (seems to cause a null pointer error on the weblogic server)
    2) setEntityContext method
    3) all methods that use the dao object.

    This depends a bit on how your DAOs are built, but you certainly don't want to instantiate a new DAO every time you need one. Unnecessary object creation is not a Good Thing.
    Generally speaking, an instance variable populated upon bean instantiation works just fine (i.e private MyDao dao = new MyDao();). If your DAO is serializable and doesn't contain any transient info of it's own, you're pretty much done since the DAO will get serialized when the bean is passivated.
    If it does contain transient data/resources (and it probably shouldn't) you can set/remove them during ejbActivate/ejbPassivate.
    If the DAO is not serializable (and it probably should be), then instantiating one during ejbActivate should not be a problem. What was the exact cause of the NPE you got?

  • Using DAO ,TO Pattern without EJB

    Hi,
    I am developing a web application without EJB. I understand those patterns need not use EJB framework. However, it smees to me that without EJB, the role of TO may be simpler.
    In my design, the meaning of TO is to separate the layer between business tier and data access tier. Upon doing some back-end enquiry, the DAO create related TO which can be translate to the business / veiw objects. And the caching will be done on Web tier but not TO layer instead.
    Am I right? Would you please give some comments? Thanks a lot.

    What is the best way to allow the client to
    interact
    with Entity objects, without exposing them. ShouldI
    implement Value objects that are easily serialized
    for transfer across the network?
    If you are not using EJB or a distributed
    architecture, you do not need DTO's or VO's. They
    are an odious construct used to obviate the
    shortcomings of remote method calls over anetwork.
    I strongly disagree.
    They are an obvious and easy model used when the
    following characteristics of a system exist.
    - Different layers.
    - Related data items that are moved throughout the
    layers.
    - Different usage of the related data items by
    different layers.
    Yes, I agree. Note the qualification 'if you are not using a distributed architecture'.
    None of that has anything to do with remote method
    calls over a network. Point of fact the first time I
    used them was in a stand alone application with no
    network traffic except that needed by the database
    driver itself.
    Simply create your domain model objects as POJO's
    s (plain ole Java objects). Persist and retrieve
    your objects via DAO's (data access objects).Your
    service layer (facade) will sit on top of thedomain
    model, encapsulating method calls into logicalunits
    of work.
    And how exactly do you move the customer
    name/customer address from the DAO to the GUI level?I am assuming the dedicated remoting product the OP specifid, Hessian, will handle moving between the tiers, or at least between the controller/view and the business tier.
    - Saish

  • Using DAO without J2EE/EJB

    Can I implement the DAO pattern in my 2-tiered application without using J2EE/EJB? My reason for using DAO is simply to insulate database changes from interface/business code and to make interface/business code easier to write.

    Sure, go ahead.

Maybe you are looking for

  • Itunes not opening after closing

    I installed iTunes 6 and after the installing and agreements and all that stuff, it was open. I was glad cuz I had to go through some steps first to get it to even show up. Everyone is having problems with this and personally it's starting to **** me

  • Why do I have to DL an app twice?

    I bought an app about the 50th anniversary of JFK's assassination from NBC and it's on the iPad and it's working just fine. However, when I plug the iPad into the computer to sync various things, it wants to download that app again. Only problem is t

  • I forgot the answers to my security questions

    I forgot the answers to my security questions and the email that gets the how to reset them no longer exists. How do I change the email that gets how to reset the answers?

  • Valid from and valid to properties under history preservation transform

    I have created_dt and last_updated both date columns in source table and also in target table. Now under history preservation transform for Date columns: For "Valid from" and "valid to" properties: which column should i pick? how can i use created_dt

  • Web-Auth with 802.1x

    Environment is WLC 2106 with 4 LWAPP access points. Currently running 2 WLANs: 1 using 802.1x authentication with a Windows IAS (RADIUS) server for Active Directory authentication; 1 using basic WEP for guest access that drops the user in it's own se