You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mark <ma...@xeric.net> on 2011/03/08 01:56:12 UTC

Could not synchronize database state with session

I'm trying to experiment with Translators and I'm running into
something I don't understand. I'm not sure if it is just a hibernate
issue or something in the way that hibernate and Tapestry are
interacting.

I have two classes:

@Entity
public class Quote {

    @ManyToOne(cascade = CascadeType.ALL)
    private Person person;

    //getters, setters, id and other fields

}

@Entity
public class Person {

    @OneToMany(cascade=CascadeType.ALL)
    private List<Quote> quotes = CollectionFactory.newList();

    //getters, setters, id and other fields
}

I'm wanting to create a translator that lets me change the person
associated with a particular quote in a simple text field in a
BeanEditForm. If you create a quote and type the name of an existing
Person object, it should use the existing person.  If you type in the
name of a new person it should create a new person.  Here is the
relevant part of the translator:

    public Person parseClient(Field field, String clientValue, String message)
            throws ValidationException {
        Person person = null;

        //If the person already exists pull them out of the database
        person = (Person)
session.createCriteria(Person.class).add(Restrictions.ilike("name",
clientValue)).uniqueResult();


        //If they they don't exist create a new person with the new name
        if(person == null) {
            logger.info("Person is null after db call- creating new person");
            person = new Person();
            person.setName(clientValue);
        }
        return person;
    }

The page that handles the BeanEditForm is very simple:

    @CommitAfter
    Object onSuccess() {
        logger.error("person id = " + quote.getPerson().getId());
        session.persist(quote);
        return "admin/AdminIndex";
    }

Everything works just fine when I create a new Quote.  A new person is
created and added to the database.  However, if I load up an existing
quote and type in a different name I get:


[WARN] util.JDBCExceptionReporter SQL Error: 0, SQLState: null
[ERROR] util.JDBCExceptionReporter failed batch
[ERROR] def.AbstractFlushingEventListener Could not synchronize
database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC
batch update
	at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)

This happens regardless of whether I type in the name of a new person
or one that is already in the database.

I looked at the hibernate debug statements and at first I thought that
when adding a new Person it might be trying to update the Quote before
the new Person was saved.  I tried explicitly saving the new Person
first, but that didn't help.  Also, I get the same error when trying
to use the name of a person that is already in the database.  I can
see from the debugging that it grabs the right person out of the
database, but I get the same error right after it shows the SQL that
will update the PERSON_QUOTE table that links the id of a person to
the id of the quote they made.

I have spent several hours going through the Hibernate forums trying
the solutions for everything similar, but nothing seems like an exact
match and none of the suggestions seemed to work.  Is there something
I'm overlooking about how Tapestry handles things that might be
causing this?

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Could not synchronize database state with session

Posted by Mark <ma...@xeric.net>.
On Mon, Mar 7, 2011 at 7:41 PM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
>> org.hibernate.exception.GenericJDBCException: Could not execute JDBC
>> batch update
>
> I don't think your error is intrinsically related to Tapestry. You're having
> some SQL error. My non-existent psychic powers (ha!) tell me this is a
> primary key violation and you're using HSQLDB 1.8, which had a bug that
> prevented the specific error to be sent to the JDBC driver when executing a
> batch execution. Use HSQLDB 2.0, which I think has this problem solved.

Well that works better. Thank you Thiago! It is much easier when it
gives you an actual error message.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Could not synchronize database state with session

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
> org.hibernate.exception.GenericJDBCException: Could not execute JDBC
> batch update

I don't think your error is intrinsically related to Tapestry. You're  
having some SQL error. My non-existent psychic powers (ha!) tell me this  
is a primary key violation and you're using HSQLDB 1.8, which had a bug  
that prevented the specific error to be sent to the JDBC driver when  
executing a batch execution. Use HSQLDB 2.0, which I think has this  
problem solved.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org