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 6115507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:05:57+00:00 2026-05-23T15:05:57+00:00

In my web app,I am using hibernate and hsqldb for database operations..and use Ant

  • 0

In my web app,I am using hibernate and hsqldb for database operations..and use Ant for build management.I have a local.properties containing db.url,db.driver etc.They contain production db values.

In hibernate.cfg.xml ,I am again providing these db parameters as properties inside SessionFactory elements.

In Ant buildfile ,I am using local.properties as the properties file so that I can create a target for starting db.

Finally ,In my dao implementation ,I am using a HibernateUtil class to create session factory
With these in place I am able to access myappdb .

My problem is that ,I need to use a different db for testing purposes.
I have some junit test classes and some cactus tests which need to work on myapptestdb.Currently what I am doing ,is replace all db related parameters in local.properties and hibernate.cfg.xml with the testdb values.

ie, replace myappdb with myapptestdb etc..
I know,this is not the correct way to do this..Can someone suggest a better solution for this?

thanks in advance,

mark

The relevant portions of various configuration files in my project are given below.

local.properties

   db.driver=org.hsqldb.jdbcDriver
    db.server.class=org.hsqldb.server.Server
    db.url=jdbc:hsqldb:hsql://localhost:9005/myappdb
    db.username=SA
    db.password=SA
    hport=9005
    dir.data=data
    halias=myappdb
    hjar=lib/hsqldb.jar
    hfile=--database.0 data/myappdb
   ...

hibernate.cfg.xml

<session-factory>
<property name="connection.driver_class">
    org.hsqldb.jdbcDriver
</property>
<property name="connection.url">
    jdbc:hsqldb:hsql://localhost:9005/myappdb;create=true
</property>
<property name="connection.username">SA</property>
<property name="connection.password">SA</property>
...
</session-factory>

build.xml

<property file="local.properties" />
...
<target name="startdb" description="start hsqldb in server mode">
        <java fork="true" classname="${db.server.class}"  >
            <classpath>
                <path location="${dir.lib}/hsqldb.jar"/>
            </classpath>
            <arg value="-database.0"/>
            <arg value="${dir.data}/${halias}"/>
            <arg value="-dbname.0"/>
            <arg value="${halias}"/>
            <arg value="-port"/>
            <arg value="${hport}"/>
        </java>
    </target>

MyDaoImpl.java

class MyDaoImpl implements MyDao {
    ...
    @Override
    public Object findById(Long id) {
        SessionFactory factory = HibernateUtil.getSessionFactory();
        Session session = factory.openSession();
        Object object = null;
        try {
            object = (Object) session.get(persistentClass, id);
            return object;
        } finally {
            session.close();
        }
    }
...
}

HibernateUtil.java

class HibernateUtil {
    private static SessionFactory sessionFactory;
    public static SessionFactory getSessionFactory() {      
        if (sessionFactory == null){
            try{
                Configuration configuration = new Configuration().configure();
                sessionFactory = configuration.buildSessionFactory();               
            }catch(HibernateException e){
                e.printStackTrace();
                throw e;
            }
        }

        return sessionFactory;
    }
}
  • 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-05-23T15:05:58+00:00Added an answer on May 23, 2026 at 3:05 pm

    Two suggestions:

    1) Move to Maven. There you can define <profiles/> which allow you to configure settings for different environments (for example, development, testing, integration testing, production). (I’m not saying you can’t do this with Ant; but it’s a lot more natural under Maven and it doesn’t require a lot of settings). You can also use resource filtering. There is also a separation between production and test code, without you having to do much more than follow a convention.

    2) In Ant, you could have two separate copies of the properties file (located in different folders or under different names) and choose one to copy under the name you need – avoiding the need for you to programatically change things. You can do this by passing in a property at build execution time.

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

Sidebar

Related Questions

I'm using Maven 2 and Hibernate for a Java web app. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I am working on a web app using C# and asp.net I have been
My web app is using GWT 2.0.2, GXT 2.1.1, Hibernate 3.5-CR1, Javassist 3.11.0 and
I want to create a web app that will use wicket, hibernate and spring
I am trying to change my web-app's JDBC code to JPA using Hibernate as
I'm using JPA over Hibernate in my web-app. Here are two entities (only getters
I'm using GWT with Hibernate, c3p0 and MySQL to produce a web app with
I am writing a web app using TurboGears, and in that app the users

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.