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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:45:20+00:00 2026-06-19T04:45:20+00:00

I have a made a sample application in Spring + Hibernate + ZK framework.

  • 0

I have a made a sample application in Spring + Hibernate + ZK framework.
In the Hibernate configuration file I have kept the property hbm2ddl.auto in “update” mode. Still Whenever I run the application again I dont get the values persisted earlier.

Following are several configuration files for reference:

BeanLocations.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- Database Configuration -->
    <import resource="../database/DataSource.xml"/>
    <import resource="../database/Hibernate.xml"/>

    <!-- Auto scan the components -->
    <context:component-scan 
        base-package="com.nagarro" />

</beans>

DataSource.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>properties/database.properties</value>
        </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <!-- <property name="hibernate.current_session_context_class" value = "${hibernate.current_session_context_class}" /> -->
    </bean>

</beans>

Hibernate.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
    xmlns:tx="http://www.springframework.org/schema/tx">

    <!-- Hibernate session factory -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>

            </props>
        </property>

        <property name="annotatedClasses">
            <list>

                <value>com.nagarro.model.ItemAttribute</value>
                <value>com.nagarro.model.ItemAttributeGroup</value>
            </list>
        </property>
    </bean>

</beans>   

Controller/ Viewmodel class

public class ItemAttributeRenderer {

    /*
     * The Logger reference variable used for Logging.
     */
    static private final Logger LOG = LoggerFactory.getLogger(ItemAttributeRenderer.class);

    @Autowired
    private ItemAttributeService itemAttrService;

    private List<ItemAttribute> itemList = new ArrayList<ItemAttribute>();

    private void prepareAndSaveItemAttributeData(){
        ItemAttribute item = null;
        int counter;
        for(int index = 0; index < 5; index++){
            counter = index+1;
            item = new ItemAttribute("Item "+counter, "Attirbute Value"+counter, "Qualifier Value"+counter);
            itemAttrService.save(item);
        }
    }
    /**
     * @return the itemList
     */
    public List<ItemAttribute> getItemList() {
        ApplicationContext appContext = new ClassPathXmlApplicationContext("/spring/config/BeanLocations.xml");
        itemAttrService = (ItemAttributeService)appContext.getBean("itemAttrService");
        prepareAndSaveItemAttributeData();
        itemList = itemAttrService.getItemAttributeList();
        return itemList;
    }

    @Command
    public void save(){
        for(ItemAttribute item : itemList){
            itemAttrService.update(item);
        }

    }

    /**
     * @param itemList the itemList to set
     */
    public void setItemList(List<ItemAttribute> itemList) {
        this.itemList = itemList;
    }
    /**
     * @return the itemAttrService
     */
    public ItemAttributeService getItemAttrService() {
        return itemAttrService;
    }
    /**
     * @param itemAttrService the itemAttrService to set
     */

    public void setItemAttrService(ItemAttributeService itemAttrService) {
        this.itemAttrService = itemAttrService;
    }



}

View file:

<?page title="Result"?>
<zk>
    <custom-attributes center="${arg.center }" />
    <window apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('com.nagarro.viewmodel.ItemAttributeRenderer')"
        title="Result Window" border="normal">
        <div>
            <grid>
                <rows>
                    <row>
                        <listbox model="@bind(vm.itemList)">
                            <listhead>
                                <listheader label="Item Name"
                                    style="text-align:center;">
                                </listheader>
                                <listheader label="Attribute Value"
                                    style="text-align:center;">
                                </listheader>
                                <listheader label="Qualifier Value"
                                    style="text-align:center;">
                                </listheader>
                            </listhead>
                            <template name="model" var="item">
                                <listitem value="${item }">
                                    <listcell label="@load(item.name)"
                                        style="text-align:center;">

                                    </listcell>
                                    <listcell style="text-align:center;">
                                    <textbox value="@bind(item.attributeValue)"
                                        style="text-align:center;"/>

                                    </listcell>
                                    <listcell
                                        label="@load(item.qualifierValue)"
                                        style="text-align:center;">
                                    </listcell>
                                </listitem>
                            </template>
                        </listbox>
                    </row>
                </rows>
            </grid>
        </div>
        <div style="text-align:right; padding:10px;">
            <button label="Save" mold="trendy"
                onClick="@command('save')">
            </button>

        </div>
    </window>
</zk>

Service class

@Service("itemAttrService")
public class ItemAttributeServiceImpl implements ItemAttributeService{

    @Autowired
    ItemAttributeDao itemAttrDao;

    public void setItemAttrDao(ItemAttributeDao itemAttrDao) {
        this.itemAttrDao = itemAttrDao;
    }


    public void save(ItemAttribute item){
        itemAttrDao.save(item);

    }

    public void update(ItemAttribute item){
        itemAttrDao.update(item);

    }

    public void delete(ItemAttribute item){
        itemAttrDao.delete(item);
    }

    public ItemAttribute findByItemAttributeName(String name){
        return itemAttrDao.findByItemAttributeName(name);
    }

    public List<ItemAttribute> getItemAttributeList(){
        return itemAttrDao.getItemAttributeList();
    }

}

DAO class

@Repository("itemAttrDao")
public class ItemAttributeDaoImpl extends CustomHibernateDaoSupport  implements ItemAttributeDao {


    public void save(ItemAttribute itemAttribute) {
        getHibernateTemplate().save(itemAttribute);
        //getHibernateTemplate().getSessionFactory().getCurrentSession().getTransaction().commit();
    }


    public void update(ItemAttribute itemAttribute) {
        getHibernateTemplate().update(itemAttribute);
        //getHibernateTemplate().getSessionFactory().getCurrentSession().getTransaction().commit();
    }


    public void delete(ItemAttribute itemAttribute) {
        getHibernateTemplate().delete(itemAttribute);
        //getHibernateTemplate().getSessionFactory().getCurrentSession().getTransaction().commit();
    }


    public ItemAttribute findByItemAttributeName(String name) {
        List list = getHibernateTemplate().find("from ItemAttribute where name=?",name);
        if(list == null){

        }else if(list.isEmpty()){

        }
        return (ItemAttribute)list.get(0);
    }


    public List<ItemAttribute> getItemAttributeList() {
        List<ItemAttribute> itemList = getHibernateTemplate().find("from ItemAttribute ");
        return itemList;
    }

}

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.abc</groupId>
    <artifactId>ZKSpringHibernateExample</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>SpringHibernateExample</name>
    <url>http://maven.apache.org</url>

    <repositories>
        <repository>
            <id>java.net</id>
            <url>http://download.java.net/maven/2/</url>
        </repository>
    </repositories>
    <properties>
        <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- Spring framework -->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>



                    <!-- MySQL database driver -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>

        <!-- Hibernate framework -->


        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.6.3.Final</version>
        </dependency>

        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>


        <!-- Hibernate library dependecy start -->
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
        </dependency>

        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.7</version>
        </dependency>
        <!-- Hibernate library dependecy end -->

        <!-- ZK Dependency start -->
        <dependency>
            <groupId>org.zkoss.zk</groupId>
            <artifactId>zkplus</artifactId>
            <version>6.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.zkoss.zk</groupId>
            <artifactId>zhtml</artifactId>
            <version>6.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.zkoss.zk</groupId>
            <artifactId>zkbind</artifactId>
            <version>6.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.zkoss.zk</groupId>
            <artifactId>zul</artifactId>
            <version>6.0.0</version>
        </dependency>
        <!-- ZK Dependency Ends -->

    </dependencies>
</project>

My problem is When I run the application again all the data that was saved earlier vanishes even though I have set the hbm2ddl.auto property to update mode.
I have set my show_sql property as “true” to check the queries that are getting fired but there are no delete queries which are getting fired.
Is there any other important thing that I am missing here.

  • 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-19T04:45:22+00:00Added an answer on June 19, 2026 at 4:45 am

    I found the solution. there were a lot of messy project dependencies in my Tomcat so I deleted that instance of Tomcat and reconfigured it for my project. Then I cleaned my project and now everything is working fine as it should be. Thanks for taking time to post the answers.

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

Sidebar

Related Questions

I have made a sample application which constructs a filter graph to capture audio
I have made a simple chat application in PHP/Ajax/MySQL. I am regularly calling these
I have made a simple test application for the issue, two winforms each containing
in my application I made a very simple binding. I have a NSMutableArray bound
I have made a sample for posting on Facebook using the basic Facebook library
I made a simple Swing application. But the rendering behaves buggy. Have I done
I am working on a simple intranet application made with Rails 3.1. I have
In my application I have a (unbalanced) tree datastructure. This tree is simply made
I'm developing an application in JSP using SimpleFormController with Spring MVC 3.0.2 using Hibernate.
I have made a simple example application to test Fluent NHibernate with the automapping

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.