2 Replies Latest reply on Aug 6, 2011 5:58 AM by Sivalingam Sivasuthan

    how to get column name of table

    Sathish kumar Govindarajan Newbie

      i converting the table into csv so i need the column name. i try to get it from entity, but it also shows transient also

        • 1. Re: how to get column name of table
          Tamas Malatinszki Newbie


          Here's one way to get column names from an entity:

          AbstractEntityPersister aep=((AbstractEntityPersister)session.getSessionFactory().getClassMetadata(ENTITYNAME.class));
          String[] properties=aep.getPropertyNames();
          for(int nameIndex=0;nameIndex!=properties.length;nameIndex++){
             System.out.println("Property name: "+properties[nameIndex]);
             String[] columns=aep.getPropertyColumnNames(nameIndex);
             for(int columnIndex=0;columnIndex!=columns.length;columnIndex++){
                System.out.println("Column name: "+columns[columnIndex]);

          Just put Your entity class name instead ENTITYNAME, and You'll see all of your variables with the definied column names.

          If You are using entityManager (em) instead hibernate session just replace session variable with (Session)em.getDelegate().

          Let me know if it works fine.


          • 2. Re: how to get column name of table
            Sivalingam Sivasuthan Newbie

            Hi Tamas,

            Thanks Tamas Its working fine and Solve my headache :)

            Best Regards,