error is not mapped [FROM <bla..bla..] in hibernate

jika anda pernah menemukkan error seperti ini:

Mar 5, 2011 2:41:36 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Mar 5, 2011 2:41:36 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
phone is not mapped [FROM phone]

k mengatasi masalah ini harusnya kita memanggil class name dari xxx.hbm.xml
misal kita mempunyai phone.hbm.xml

<hibern
untuate-mapping>
  <class name="org.phonebook.model.PhoneMod" table="phone">
    <id column="ID_PHONE" name="id" type="int">
...

nah diatas terdapat class name =”org.phonebook.model.PhoneMod” class itulah yg kita gantikan pada pemanggilan database.seperti ini:
class sebelum diganti:

    public List getAllPhone()throws Exception{
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        List ls = new ArrayList();
        try{
            ls = session.createQuery("FROM phone").list();
            session.getTransaction().commit();
        }catch(Exception e){
            System.out.println(e.getMessage());
            session.getTransaction().rollback();
        }
        return ls;
    }

sesudah diganti:

    public List getAllPhone()throws Exception{
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        List ls = new ArrayList();
        try{
            ls = session.createQuery("FROM org.phonebook.model.PhoneMod").list();
            session.getTransaction().commit();
        }catch(Exception e){
            System.out.println(e.getMessage());
            session.getTransaction().rollback();
        }
        return ls;
    }

nah dengan penggantian ini maka app akan berjalan..

semoga bermanfaat…:D

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s