Does hibernate support getting data from Database Views?

Discussions

General J2EE: Does hibernate support getting data from Database Views?

  1. We are using Oracle. I am trying to get data from oracle view.

    I tried creating mapping file for a class representing a view, and it didnot allowed me (hibernate.cfg.xml schema -- has class element, which doesnot have any attributes for supporting view, it has one for table).

    I tried using plain reflection, plain sql, it still required class to be persistent (class should have hibernate mapping).

    Does any one know wether its possible, whats the best way to do it?

    Thanks,
    Mehul

    Threaded Messages (8)

  2. Hi, have you already found an answer to this question? As a hibernate newbie I'm currently asking myself the same (for PostgreSQL).

    Thanks,

    Oliver
  3. Hi Oliver,

    This is a must have feature for an ORM tool, it should atleast support simple
    reflection with no mapping required at the minimum.

    I have not found the answer. Team here has no clue either :)
    Waiting for some one from hibernate team to clarify.

    Mehul
  4. Hi,

    Yes you can use hibernate with views.

    Just put your view name in the table attribute.

    Here's a mapping I've got for one of our views:

    <class name="EnterpriseProject" table="VW_ENTERPRISE_PROJECTS">
    <cache usage="read-only"/>
    <id name="id" column="project_id" type="string" unsaved-value="null">
    <generator class="assigned" />
    </id>
    <property name="title" />
    <property name="description" />
    <property name="stage" />
    <property name="lob" />
    <property name="projectManager" column="project_manager_name" />
    </class>

    Hope this helps,

    Gareth
  5. Hi,

    Yes you can use hibernate with views.

    Just put your view name in the table attribute.

    Here's a mapping I've got for one of our views:













    Hope this helps,

    Gareth
  6. Got Error[ Go to top ]

    it's not working. Got error org.hibernate.hql.ast.QuerySyntaxException: [VIEW_NAME] is not mapped. Any idea ?
  7. Got Error[ Go to top ]

    You should use the name of the Java class that you're mapping to the database view. If we take a simple example of one entity being mapped to one table. If you have given Entity name as "User" and the POJO name is "UserEntity" then you should query "from UserEntity" else if you say "from User" , you'll get a similar error saying "User is not mapped". Regards Prince
  8. Got Error[ Go to top ]

    You should use the name of the Java class that you're mapping to the database view. If we take a simple example of one entity being mapped to one table. If you have given Entity name as "User" and the POJO name is "UserEntity" then you should query "from UserEntity" else if you say "from User" , you'll get a similar error saying "User is not mapped". Regards Prince
  9. Continue ...[ Go to top ]

    My vie wname is vCustomerList Java Code: Query query = session.createQuery ( "from vCustomerList Order By UPPER(CustomerName)" ); Got same error: Query query = session.createQuery ( "Select CustomerName,... from vCustomerList Order By UPPER(CustomerName)" ); Got error: org.hibernate.hql.ast.QuerySyntaxException: vCustomerList is not mapped [from vCustomerList Order By UPPER(CustomerName)]