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

  • Home
  • SEARCH
  • 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 3496786
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:17:29+00:00 2026-05-18T12:17:29+00:00

I am getting a hibernate error. I am just doing a proof of concept

  • 0

I am getting a hibernate error. I am just doing a proof of concept to test for association in hibernate. I am almost sure that the error i think lies in the mapping file but i cannot figure it

The example I am using is that a USER can have many COMPUTER but a COMPUTER is only for one USER

my ModuleLoad a bit analogous to main in Java

public void onModuleLoad() 
    {
        GreetingServiceAsync S = GWT.create(GreetingService.class);
        ((ServiceDefTarget) S).setServiceEntryPoint( GWT.getModuleBaseURL() +"greet");

        Computer C1= new Computer(1,"ad");
        Computer C2= new Computer(2,"ad");
        Computer C3= new Computer(3,"ad");
        Set <Computer> S1= new HashSet();
        S1.add(C2);S1.add(C3);S1.add(C1);

        Users U1= new Users(1,S1);
        S.greetServer(U1, new AsyncCallback <Users>(){

            @Override
            public void onFailure(Throwable caught) {
                // TODO Auto-generated method stub
                Window.alert("Failure");

            }

            @Override
            public void onSuccess(Users result) {
                // TODO Auto-generated method stub
                Window.alert("Success");
            }});

    }

The Users class:

    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;

    import net.sf.gilead.pojo.gwt.LightEntity;

    import com.google.gwt.user.client.rpc.IsSerializable;

    public class Users extends LightEntity implements IsSerializable
    {
        private long UserId;
        private Set <Computer> Computers=new HashSet <Computer> ();

        public Users(){}
        public Users(long userId, Set <Computer> computers) 
        {
            UserId = userId;
            Computers = computers;
        }
        public long getUserId() {
            return UserId;
        }
        public void setUserId(long userId) {
            UserId = userId;
        }
        public Set <Computer> getComputers() {
            return Computers;
        }
        public void setComputers(Set<Computer> computers) {
            Computers = computers;
        }
    }

Computer Class:

    import net.sf.gilead.pojo.gwt.LightEntity;

    import com.google.gwt.user.client.rpc.IsSerializable;

    public class Computer extends LightEntity implements IsSerializable
    {
        private long ComputerId;
        private String Description;

        public Computer(){}
        public Computer(long ComputerId,String Description)
        {
            this.ComputerId=ComputerId;
            this.Description=Description;
        }

        public long getComputerId() {
            return ComputerId;
        }
        public void setComputerId(long computerId) {
            ComputerId = computerId;
        }
        public String getDescription() {
            return Description;
        }
        public void setDescription(String description) {
            Description = description;
        }
    }

Users Mapping File:
  <?xml version="1.0"?>
        <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
        <!-- Generated Dec 3, 2010 5:21:42 AM by Hibernate Tools 3.4.0.Beta1 -->
        <hibernate-mapping>
            <class name="com.BiddingSystem.domain.Users" table="USERS">
                <id name="UserId" type="long">
                    <column name="USERID" />
                    <generator class="assigned" />
                </id>
                <set name="Computers" table="COMPUTER" inverse="false" lazy="true">
                    <key>
                        <column name="USERID" />
                    </key>
                    <one-to-many class="com.BiddingSystem.domain.Computer" />
                </set>
            </class>
        </hibernate-mapping>

Computer Class:

import net.sf.gilead.pojo.gwt.LightEntity;

import com.google.gwt.user.client.rpc.IsSerializable;

public class Computer extends LightEntity implements IsSerializable
{
    private long ComputerId;
    private String Description;

    public Computer(){}
    public Computer(long ComputerId,String Description)
    {
        this.ComputerId=ComputerId;
        this.Description=Description;
    }

    public long getComputerId() {
        return ComputerId;
    }
    public void setComputerId(long computerId) {
        ComputerId = computerId;
    }
    public String getDescription() {
        return Description;
    }
    public void setDescription(String description) {
        Description = description;
    }
}

Computer Mapping File:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 3, 2010 5:21:42 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
    <class name="com.BiddingSystem.domain.Computer" table="COMPUTER">
        <id name="ComputerId" type="long">
            <column name="COMPUTERID" />
            <generator class="assigned" />
        </id>
        <property name="Description" type="java.lang.String">
            <column name="DESCRIPTION" />
        </property>
    </class>
</hibernate-mapping>

Hibernate Configuration File:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost/postgres</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">noor</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="show_sql">true</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="current_session_context_class">thread</property> 
        <mapping resource="com/BiddingSystem/domain/Users.hbm.xml"/>
        <mapping resource="com/BiddingSystem/domain/Computer.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

Server implementation to save the to the database:

import java.util.ArrayList;
import java.util.List;

import net.sf.gilead.core.PersistentBeanManager;
import net.sf.gilead.core.hibernate.HibernateUtil;
import net.sf.gilead.core.store.stateless.StatelessProxyStore;
import net.sf.gilead.gwt.PersistentRemoteService;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.BiddingSystem.client.GreetingService;

import com.BiddingSystem.domain.Users;


import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class GreetingServiceImpl extends PersistentRemoteService implements GreetingService 
{

    private static final long serialVersionUID = 1L;
    private HibernateUtil gileadHibernateUtil = new HibernateUtil();
    public GreetingServiceImpl ()
    {
         gileadHibernateUtil.setSessionFactory(com.BiddingSystem.server.HibernateUtil.getSessionFactory());

                PersistentBeanManager persistentBeanManager = new PersistentBeanManager();
                persistentBeanManager.setPersistenceUtil(gileadHibernateUtil);
                persistentBeanManager.setProxyStore(new StatelessProxyStore());

                setBeanManager(persistentBeanManager);
    }

    public Users greetServer(Users S) 
    {
        Session session = gileadHibernateUtil.getSessionFactory().openSession();
        Transaction tr= session.beginTransaction();
        session.save(S);
        tr.commit();
        session.close();
         return S;
      }


}

The Error I am getting:

Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
    at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
    at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:183)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
    at com.BiddingSystem.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at net.sf.gilead.gwt.PersistentRemoteService.processCall(PersistentRemoteService.java:174)
    ... 21 more

Users Mapping File:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 3, 2010 5:21:42 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
    <class name="com.BiddingSystem.domain.Users" table="USERS">
        <id name="UserId" type="long">
            <column name="USERID" />
            <generator class="assigned" />
        </id>
        <set name="Computers" table="COMPUTER" inverse="false" lazy="true">
            <key>
                <column name="USERID" />
            </key>
            <one-to-many class="com.BiddingSystem.domain.Computer" />
        </set>
    </class>
</hibernate-mapping>

The other file are sure to be good as I have tested them without hibernate

If anyone can help, it would be great

  • 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-18T12:17:30+00:00Added an answer on May 18, 2026 at 12:17 pm

    With the assigned generator in hibernate, you need to choose a different unsaved-value to tell hibernate to determine whether to INSERT or UPDATE. The default implementation looks to see if the id column is null. Since you’re assigning the manually, even unsaved entities will have an id, and Hibernate will try to do an UPDATE instead of an INSERT.

    Read the ID section (specifically 5.1.2.2.5) of the Hibernate documentation

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

Sidebar

Related Questions

Exception in thread main java.lang.NullPointerException at com.hibernate.UserDAO.findAll(UserDAO.java:154) at test.main(test.java:12) I am getting this error
I'm getting this Hibernate error: org.hibernate.MappingException: Could not determine type for: a.b.c.Results$BusinessDate, for columns:
I'm trying to access the current hibernate session in a test case, and getting
I am getting an error with Hibernate (I am not too familiar the API
I am getting this error. I have my hibernate connections and MVC all setup
I am getting the folloinwg error from NHibernate: System.ObjectDisposedException: Session is closed! Object name:
We are getting this error after upgrading to NHibernate 2.1. [QueryException: Cannot simultaneously fetch
I am getting the following error when trying to update an object using nhibernate.
I'm getting started in Hibernate and so far it's not too hard. But I
I am getting the following exception while adding data into database: org.hibernate.HibernateException: The database

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.