Announcement Announcement Module
Collapse
No announcement yet.
Table mapping problem with Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Table mapping problem with Hibernate

    Hi!
    i am getting org.hibernate.hql.ast.QuerySyntaxException, saying that my table is not mapped.

    this is my vo class
    Code:
    package src.vo;
    import java.io.Serializable;
    import javax.persistence.*;
    @Entity
    @Table (name="DUAL")
    
    public class Dual implements Serializable{
    	private String dummy;
    
    	@Id
    	public String getDummy() {
    		return dummy;
    	}
    	public void setDummy(String dummy) {
    		this.dummy = dummy;
    	}
    }
    and this is my hibernate.cfg.xml
    Code:
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>	
     <session-factory>
      <mapping class="src.vo.User"/>
      <!-- and another vo object-mappings, that are working perfectly-->
    
      <mapping class="src.vo.Dual"/>
     </session-factory>
    </hibernate-configuration>
    i do NOT mention dual table in any another conf file, because it is a sytem table, needet to access special querries just to obtain some data from the database, that do NOT depend on any bussines object, like:
    Code:
    select rpdfunctions.get_last_report_date(trunc(sysdate)) from dual
    this one retuns the last work day of the company. there is no data in this table. only dummy field just to have one...
    can somebody tell me what am i forgetting? thank you
    Last edited by orusso; May 23rd, 2006, 12:56 PM.

  • #2
    is the problem with id beeing String?

    Comment


    • #3
      For this kind of scenarios, I would use hibernate native SQL queries support.

      HTH.

      Comment


      • #4
        Originally posted by irbouho
        For this kind of scenarios, I would use hibernate native SQL queries support.

        HTH.
        Thank you for your reply! I had that idea too, but when i tried to implemet it, i had one problem. When i tried to get one session from my hibernateTemplate:
        getHibernateTemplate().getSession()
        i recived this error:
        The method getSession() from the type HibernateTemplate is not visible.

        i was successful to do what i wanted with the folowing code (just to help if some other begginer would have the same problem :-) ):
        getHibernateTemplate().getSessionFactory().openSes sion().createSQLQuery("select xxxxxx from dual");

        Thank you again.

        Comment


        • #5
          Originally posted by orusso
          getHibernateTemplate().getSessionFactory().openSes sion().createSQLQuery("select xxxxxx from dual");
          I would rather propose to use HibernateTemplate#execute, passing in a HibernateCallback. Within that callback you have access to the session.

          Circumventing this mechanism by accessing the SessionFactory directly may conflict with Spring's session management.

          Regards,
          Andreas

          Comment


          • #6
            Originally posted by orusso
            getHibernateTemplate().getSessionFactory().openSes sion().createSQLQuery("select xxxxxx from dual");
            I would suggest using
            Code:
            SessionFactoryUtils.getSession(getHibernateTemplate().getSessionFactory())
            This way, you take advantage of Spring Session management.

            HTH.

            Comment

            Working...
            X