Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7871651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:58:10+00:00 2026-06-03T01:58:10+00:00

Im using Hibernate to save a Java class to a derby database. When I

  • 0

Im using Hibernate to save a Java class to a derby database.
When I run my code everything is fine the first time I run my class ,I can create and call back an instance from my database and it persists even while I turn off my server Tomcat.

When I load back up my server I found that my database tables get wiped once I return the following class, which function isto create a sessionfactory that I use to create my sessions, so i dont have multiple factories, Its called by a ServletContextListener so that its called before any of my servevlets are called and therefore maintain one Factory per run.

Does anyone know why it keeps wiping my database, is it not just a handle

public class CreateMysessionfactory {
private SessionFactory factory;

public CreateMysessionfactory() {

    AnnotationConfiguration config = new AnnotationConfiguration();

    config.addAnnotatedClass(UPS.class);

    config.configure();

    factory = config.buildSessionFactory();

}

public SessionFactory getFactory() {
    return factory;
}

Below is the ServletContextListener calling the above method, it might be helpfull.

    public void contextInitialized(ServletContextEvent event) {
    // Create the database connection.
    ServletContext ctx = event.getServletContext();

    // Create the database:grab my hibernate object here
    CreateMysessionfactory db = new CreateMysessionfactory();
    ctx.setAttribute("db", db);

    ctx.setAttribute("DbSessionFactory", db.getFactory());

    ItemDataAccessObject dao = new ItemDataAccessObject(db.getFactory());
    Item u = new Item();
    //Item u =dao.getItem(0);
    dao.updateItem(u);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:58:12+00:00Added an answer on June 3, 2026 at 1:58 am

    all the entities are bieng deleted on startup because you have set the hibernate config the same way,

    actually the property HBM2DDl has these values validate | update | create | create-drop

    you might have set it as create-drop which means , delete and create the fresh schema on startup and hence the effect.

    you may like to change the value to validate, which just conforms that the schema is intact

    Refer the link if you need further details http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my problem is that, i want to save class object java.lang.reflect.Field into database using
I'm using JPA (Hibernate implementation) to save objects to the database. Selecting works fine,
Using hibernate, how can I persist a class with a List<String> field? Consider the
I have a com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException in my code (using Hibernate and Spring) and I can't
We have a Oracle Date column. At first in our Java/Hibernate class we were
I have below method to save an object to database using Hibernate but I
If I save an entity using a Hibernate session, and then probe to get
when using hibernate with spring, can someone explain how the session unit of work
Hi I am using hibernate and Mysql. I have a class with a boolean
I'm using hibernate validators with JSF. How can I set my conversion error messages?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.