5 Replies Latest reply on Nov 23, 2007 12:47 AM by paradigmza

    Seam and plain old JDBC code

    syncro

      Hey all

      I understand that to be truly efficient with Seam you need to run some sort of ORM tool (Hibernate preferably). At our company we are in desperate need of introducing a web framework and i'm thinking of using Seam, but our db persistence code is all JDBC. Is it still worth using Seam, or should I consider a more "lightweight" and less obtrusive framework? We are planning on replacing all of our JDBC code with Hibernate in the near future, but this will be after the introduction of the new web framework.

        • 1. Re: Seam and plain old JDBC code
          christian.bauer

          Depends what the API of your persistence code is. If you call loadThatStuff() and an instance of some domain object is returned, that should work just fine. JSF, Seam, and so on are really based on domain objects with property accessor methods and collections. It will be a bit more work for you to implement saveModifiedData(object) of course (this is what an ORM can do automatically, generate the SQL).

          On the other hand, if your persistence code only returns tabular resultsets, and expects handwritten UPDATE, DELETE, and INSERT statements, or if it uses a Java RowSet to capture modifications, things become more difficult. You'd need to copy stuff manually between domain objects and resultsets. You could also consider using Hibernate as a resultset-to-object-mapper, and migrate your own SQL:

          http://blog.hibernate.org/cgi-bin/blosxom.cgi/2004/08/23#customsql
          http://blog.hibernate.org/cgi-bin/blosxom.cgi/2004/06/23#comparingpersistence

          • 2. Re: Seam and plain old JDBC code
            christian.bauer

            By the way, if you migrate your SQL stuff into Hibernate, and if you use the StatelessSession API of Hibernate 3.x, you will get a very simple JDBC command persistence layer, without all the fancy new semantics of a "full" ORM (no object dirty checking, no caching, no cascading, etc). Hibernate then basically just acts as a command bridge for SQL operations, but returns and accepts domain objects.

            • 3. Re: Seam and plain old JDBC code
              gavin.king

               

              I understand that to be truly efficient with Seam you need to run some sort of ORM tool


              ORM definitely helps you be efficient, but Seam can help you be more efficient even without it. The only real requirement is that data in your Java code is represented as JavaBeans.

              For example, you could use iBATIS with Seam - it would not be as nice, IMO, but nor would it feel wrong.

              • 4. Re: Seam and plain old JDBC code
                fangzx

                How to use plain old JDBC code with Seam? Could anyone show some code pls? Thanks in advance.

                • 5. Re: Seam and plain old JDBC code
                  paradigmza

                   

                   @Resource(mappedName = "java:/someDatasource")
                   DataSource someDataSource;
                  



                  Then you can get the Connection from that an do "normal" jdbc

                  Connection conn;
                   try {
                   conn = someDataSource.getConnection();
                   } catch (SQLException e) {
                   throw new SomeExceptions_Exception(
                   "Could not get connection", null, e);
                   }