2 Replies Latest reply on Aug 18, 2009 6:39 PM by daxxy

    how to access mysql view from hibernate query?

    navintamil

      can anyone tell me the answer for my question?


      normally using hibernate query at jboss seam application ,
      directly  write select query and assigning corresponding list of object. but i want to assign the view(Data Base) into list of object .is there any possibilities for access view from hibernate query ?

        • 1. Re: how to access mysql view from hibernate query?

          yes this is possible:


          check
          Hibernate Doc


          and


          Hibernate Doc
          (chapter 2.3.2. Mapping native queries)


          Greetz Marco

          • 2. Re: how to access mysql view from hibernate query?
            daxxy

            I just used seam-gen to generate entities and views and it treated the MySQL view the same as a table. It worked just fine.  The only thing I had to do was explicitly specify a primary key in my reverse engineering file, seam-gen.reveng.xml.


            Like this:




            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
            <hibernate-reverse-engineering>
                 <table name="office_view">
                      <primary-key>
                           <key-column name='office_id' />
                      </primary-key>
                 </table>
            </hibernate-reverse-engineering>