facebook

HQLEditor not working

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #287898 Reply

    jadeite1000
    Member

    Hi All:

    I am using MyEclipse 6.5.1 with Hibernate 3.2.6 that comes with MyEclipse jars for Hibernate.
    I was able to use hql in my java code.
    When I tried to used the MyEclipse HQL Editor, I get the following error:
    org.hibernate.hql.ast.QuerySyntaxException:User is not mapped[from User]
    My User is using Hibernate Annotations.
    Does MyEclipse 6.5.1 HQL Editor supports annotations.
    Here is my hibernate.cfg.xml file:
    <?xml version=’1.0′ encoding=’UTF-8′?>
    <!DOCTYPE hibernate-configuration PUBLIC
    “-//Hibernate/Hibernate Configuration DTD 3.0//EN”
    http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”&gt;
    <hibernate-configuration>
    <session-factory>
    <property name=”connection.url”>jdbc:mysql://localhost/examscam</property>
    <property name=”connection.username”>root</property>
    <property name=”connection.driver_class”>com.mysql.jdbc.Driver</property>
    <property name=”dialect”>org.hibernate.dialect.MySQLDialect</property>
    <property name=”connection.password”>mychau1</property>
    <property name=”transaction.factory_class”>org.hibernate.transaction.JDBCTransactionFactory</property>
    <!– thread is the short name for
    org.hibernate.context.ThreadLocalSessionContext
    and let Hibernate bind the session automatically to the thread
    –>
    <property name=”current_session_context_class”>thread</property>
    <!– this will show us all sql statements –>
    <property name=”hibernate.show_sql”>true</property>
    <!– this drop the existing database and create a new one –>

    <property name=”hibernate.current_session_context_class”>org.hibernate.context.ThreadLocalSessionContext</property>
    <!– mapping files –>
    <property name=”hibernate.mapping.precedence”>class, hbm</property>
    <mapping class=”com.examscam.model.User”/>
    </session-factory>
    </hibernate-configuration>

    Here is my java code for User.java:
    package com.examscam.model;

    import java.util.Calendar;
    import java.util.List;

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;

    import org.hibernate.HibernateException;
    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.AnnotationConfiguration;
    import org.hibernate.cfg.Configuration;
    import com.examscam.HibernateUtil;

    import javax.persistence.Column;
    import com.examscam.HibernateUtil;
    import org.hibernate.tool.hbm2ddl.SchemaExport;
    import javax.persistence.Table;
    import javax.persistence.Column;

    import javax.persistence.Transient;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
    import javax.persistence.Basic;


    @Entity

    @Table (name=”user”, schema=”examscam”)
    public class User
    {
    private Long id;
    private String password;
    private String loginName;
    private String encryptedPassword;
    private String emailAddress;
    private Boolean verified;
    private java.util.Date lastAccessTime;
    private java.util.Calendar registrationDate;

    @Id
    @GeneratedValue
    @Column(name=”id”)
    public Long getId()
    {
    return id;
    }

    public void setId(Long id)
    {
    this.id = id;
    }

    @Column (name=”password”)
    public String getPassword()
    {
    return password;
    }

    public void setPassword(String password)
    {
    this.password = password;
    }

    @Transient
    public String getEncryptedPassword() {
    return encryptedPassword;
    }

    public void setEncryptedPassword(String encryptedPassword) {
    this.encryptedPassword = encryptedPassword;
    }
    @Column (name=”login_name”)
    public String getLoginName()
    {
    return loginName;
    }

    public void setLoginName(String loginName) {
    this.loginName = loginName;
    }

    public String getEmailAddress() {
    return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
    this.emailAddress = emailAddress;
    }

    public Boolean getVerified() {
    return verified;
    }

    @Basic
    public void setVerified(Boolean verified) {
    this.verified = verified;
    }

    @Temporal(TemporalType.TIMESTAMP)
    public java.util.Date getLastAccessTime() {
    return lastAccessTime;
    }

    public void setLastAccessTime(java.util.Date lastAccessTime) {
    this.lastAccessTime = lastAccessTime;
    }

    @Temporal(TemporalType.DATE)
    public java.util.Calendar getRegistrationDate() {
    return registrationDate;
    }

    public void setRegistrationDate(java.util.Calendar registrationDate){
    this.registrationDate = registrationDate;
    }

    public static void main(String args[])
    {
    Session session = HibernateUtil.beginTransaction();
    try
    {
    Query query = session.createQuery(“from User”);
    List users = query.list();

    for (int i=0; i<users.size();i++)
    {
    User user = (User)users.get(i);
    System.out.println(user.getLoginName());
    }
    session.getTransaction().commit();

    }
    catch(HibernateException e)
    {
    e.printStackTrace();
    session.getTransaction().rollback();
    session.close();
    throw e;
    }
    }

    }

    The java code works if I runned the java code only. I only have problem with the MyEclipse 6.5 HQL Editor.

    Yours,

    Frustrated.

    #287942 Reply

    Brian Fernandes
    Moderator

    Hi,

    When you created this project, did you use Hibernate 3.2 and enable annotations support? Or did you continue to use an older project and added the Hibernate 3.2 libraries? You can check the Hibernate version of your project under Project properties > MyEclipse > Hibernate, it should say Hibernate 3.2.

    The HQL editor will not support annotation configurations unless the Hibernate version of the project is 3.2, we an provide further instructions based on your configuration.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: HQLEditor not working

You must be logged in to post in the forum log in