简体   繁体   中英

Hibernate, Update Form bean giving error?

In my Java Application i've a table User, and this table have only one value (this is important only one value in the database).

Now just i'm update the User table using UserVO bean..

it is a just simple update logic

    public void updateUserVO(UserVO uservo)throws DataAccessException {
    -------//set values
    entityManager.merge(uservo);
    entityManager.flush();
}

But i'm getting

    SEVERE: Servlet.service() for servlet [spring] in context with path [/EClass] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.HibernateException: More than one row with the given identifier was found: U1, for class: com.sits.ec.valueObjects.UserVO] with root cause
org.hibernate.HibernateException: More than one row with the given identifier was found: U1, for class: com.sits.ec.valueObjects.UserVO
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:108)
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
    at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3294)
    at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
    at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
    at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
    at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
    at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
    at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
    at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
    at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)
    at org.hibernate.type.EntityType.resolve(EntityType.java:438)
---------

And funny thing is ... Same code run another system and in that have also only one column in Database..

And i have nearly 10 update operations their with same User object ( id=U1 ) one hour back that code working perfectly, but now not working at least one .. every Updated operation giving above error.

Specifications:  OS - Ubuntu(Linux) 

Database - MySql (Lamp Sever) . Please help me how to solve this one..

the important part of the stacktrace is

at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)

when you are calling merge (with a detached entity i guess) it tries to load the entity by it's primary key. this fails because more than one object is returned. look in to your database you are having more than one row with the same value for this one column. so this table does really have only one row or are there more but you are only mapping this one? are you updating the primary key? i can imagine orm-frameworks having problems with this, introduce another column for the value that you want to update if that is so. what kind of property is this your are updating.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM