facebook

hibernate DEMO BasicDB

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

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

    Andrew Cheng
    Participant

    I watch the demo VipService was generate file->new->classes
    , but suddenly it is full of codes, where are those codes come from?

    😮

    /**
    * getInstance() returns the instance of the <code>VipService</code> singleton.
    *
    * @return <code>VipService</code> singleton.
    */
    public static synchronized VipService getInstance()
    {
    /*
    * Creates the Singleton instance, if needed.
    *
    */
    if (instance == null)
    {
    instance = new VipService();
    }
    return instance;
    }

    /**
    * getVipdata() returns <code>Vipdata</code> object from database with given id. If
    * the user is not found, will return null.
    *
    * @param id The <code>Long</code> id of desired <code>Vipdata</code>
    * @return <code>Vipdata</code> with given id, if it exists. Otherwise, returns null.
    */
    public Vipdata getVipdata(Long id)
    {
    /*
    * Use the ConnectionFactory to retrieve an open
    * Hibernate Session.
    *
    */
    Session session = null;

    try
    {
    session = SessionFactory.currentSession();
    /*
    * Calls the load method on the Hibernate session object
    * to retrieve the Item with the provided id.
    */
    return (Vipdata) session.load(Vipdata.class, id);
    }
    /*
    * If the object is not found, i.e., no Item exists with the
    * requested id, we want the method to return null rather
    * than throwing an Exception.
    *
    */
    catch (ObjectNotFoundException onfe)
    {
    return null;
    }
    catch (HibernateException e)
    {
    /*
    * All Hibernate Exceptions are transformed into an unchecked
    * RuntimeException. This will have the effect of causing the
    * user’s request to return an error.
    *
    */
    System.err.println(“Hibernate Exception” + e.getMessage());
    throw new RuntimeException(e);
    }
    /*
    * Regardless of whether the above processing resulted in an Exception
    * or proceeded normally, we want to close the Hibernate session. When
    * closing the session, we must allow for the possibility of a Hibernate
    * Exception.
    *
    */
    finally
    {
    if (session != null)
    {
    try
    {
    session.close();
    }
    catch (HibernateException e)
    {
    System.err.println(“Hibernate Exception” + e.getMessage());
    throw new RuntimeException(e);
    }

    }
    }

    }

    /**
    * updateItem() updates specfied <code>Item</code> through Hibernate.
    *
    * @param item An <code>Item</code> to be updated
    */
    public void updateVipdata(Vipdata vipdata)
    {
    /*
    * Use the ConnectionFactory to retrieve an open
    * Hibernate Session.
    *
    */

    Session session = null;
    try
    {
    session = SessionFactory.currentSession();
    /*
    * Update the state of the item using the Hibernate session’s update method.
    *
    * Call the flush method to ensure that the object in saved.
    *
    */
    session.update(vipdata);
    session.flush();
    }
    catch (HibernateException e)
    {
    System.err.println(“Hibernate Exception” + e.getMessage());
    throw new RuntimeException(e);
    }
    /*
    * Regardless of whether the above processing resulted in an Exception
    * or proceeded normally, we want to close the Hibernate session. When
    * closing the session, we must allow for the possibility of a Hibernate
    * Exception.
    *
    */
    finally
    {
    if (session != null)
    {
    try
    {
    session.close();
    }
    catch (HibernateException e)
    {
    System.err.println(“Hibernate Exception” + e.getMessage());
    throw new RuntimeException(e);
    }

    }
    }

    }

    /**
    * getItemList() returns list of all <code>Item</code> objects stored in the database.
    *
    * @return <code>List</code> of <code>Item</code> objects.
    */
    public List getVipdataList()
    {
    /*
    * Use the ConnectionFactory to retrieve an open
    * Hibernate Session.
    *
    */
    Session session = null;

    try
    {
    session = SessionFactory.currentSession();
    /*
    * Build HQL (Hibernate Query Language) query to retrieve a list
    * of all the items currently stored by Hibernate.
    */
    Query query =
    session.createQuery(
    “select Vipdata from com.nscorp.hibernate.Vipdata Vipdata order by Vipdata.vipName”);
    return query.list();

    }
    catch (HibernateException e)
    {
    System.err.println(“Hibernate Exception” + e.getMessage());
    throw new RuntimeException(e);
    }
    /*
    * Regardless of whether the above processing resulted in an Exception
    * or proceeded normally, we want to close the Hibernate session. When
    * closing the session, we must allow for the possibility of a Hibernate
    * Exception.
    *
    */
    finally
    {
    if (session != null)
    {
    try
    {
    session.close();
    }
    catch (HibernateException e)
    {
    System.err.println(“Hibernate Exception” + e.getMessage());
    throw new RuntimeException(e);
    }

    }
    }
    }

    /**
    * addItem() inserts new <code>Item</code> into the database through Hibernate.
    *
    * @param item A new <code>Item</code> to be added.
    */
    public void addVipdata(Vipdata data)
    {

    Session session = null;

    try
    {
    session = SessionFactory.currentSession();
    session.save(data);
    session.flush();
    }
    catch (HibernateException e)
    {
    System.err.println(“Hibernate Exception” + e.getMessage());
    throw new RuntimeException(e);
    }
    /*
    * Regardless of whether the above processing resulted in an Exception
    * or proceeded normally, we want to close the Hibernate session. When
    * closing the session, we must allow for the possibility of a Hibernate
    * Exception.
    *
    */
    finally
    {
    if (session != null)
    {
    try
    {

    session.close();
    }
    catch (HibernateException e)
    {
    System.err.println(“Hibernate Exception” + e.getMessage());
    throw new RuntimeException(e);
    }

    }
    }

    }

    #217799

    Riyad Kalla
    Member

    This looks like generated Hibernate classes from our tool.. is that what you did?

    #217818

    Andrew Cheng
    Participant

    How it is generated?

    #217867

    Riyad Kalla
    Member

    Using the database explorer, you can navigate to a table in your database, right click, and then create the hibernate mappings for that table.

    #217918

    Andrew Cheng
    Participant

    I do not see it generate

    Query query =

    session.createQuery(
    “select Vipdata from com.nscorp.hibernate.Vipdata Vipdata order by Vipdata.vipName”);
    return query.list();

    #217937

    support-jeff
    Member

    This is not the code generated by hibernate tool in ME. No clue where it comes from. Was this something you imported from a file?

    #218273

    Andrew Cheng
    Participant

    if you run the demo, can you tell me where these code come from.
    I download the demo source code, and don’t know where it come from
    during the demo process.

    #218275

    support-jeff
    Member

    You will need to talk to the author of the demo. The code in question is not generated by ME. The demo was contributed by a user, so you need to contact them directlyt.

    #237956

    lhale
    Participant

    This message has not been recovered.

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: hibernate DEMO BasicDB

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