2 Replies Latest reply on Jan 2, 2008 9:51 AM by breako

    Determining Database Type.

    breako

      Hi,
      I have an EntityManager and I want to determine database type. This not part of the JPA spec, however some JPA vendors e.g. hibernate have a getConnection() API in their EntityManager implementation.
      If you cast to this implementation and get a connection you can determine database type.

      If using Seam Managed EntityManager, Seam injects a org.jboss.seam.persistence.EntityManagerProxy instance. So this API is not available.
      Is there any other way I can determine database type?

      Reason I ask is because, we have to support a number of different database types and have to be able to determine dynamically and at runtime the database type to handle some custom stuff.

      Regards

        • 1. Re: Determining Database Type.
          pmuir

          Use getDelegate to get the underlying JPA provider.

          • 2. Re: Determining Database Type.
            breako

             

            "pete.muir@jboss.org" wrote:
            Use getDelegate to get the underlying JPA provider.

            Thanks for that Peter.
            The complete solution just in case anyone is interested is:
            Object localEMObject = ((EntityManagerProxy)em).getDelegate();
            HibernateSessionProxy hsb = (HibernateSessionProxy)localEMObject;
            connection = hsb.connection();
            DatabaseMetaData dbMD = connection.getMetaData();
            String database = dbMD.getDatabaseProductName();
            


            This forum is very good btw.