-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: session.update(object) produces SQL INSERT
PostPosted: Wed Jul 19, 2006 10:37 am 
Newbie

Joined: Wed Jul 19, 2006 9:08 am
Posts: 2
Location: London, UK
Hi,

I have a very very odd error that does occurs on our live server every 3-4 days and we could not replicate.

I create and persist an object (Person) to the database. User are then taken to the external payment system (WorldPay) and I use session.update to update Person with transaction ID and other stuff.

It looks like that every 3-4 days the person is not updates but inserted as a new record (new ID is set).

This bugs us very much because the person who register and pays can signup more people (all Person objects) and INSERT detaches him from the group. A group consists of people whose Group field equals applicants ID.

The problem is we cannot reproduce the error and cannot really turn the debugging on a very busy live server.

How is it possible that session.update(object) produces SQL INSERT?

I would be greatfull if someone could help me here. Many thanks in advance.

Hibernate version:

Hibernate 3.1.1

Mapping documents:
...
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@live1:1521:live1</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property>

<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property>
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">100</property>

<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.OSCacheProvider</property>

<property name="cache.use_query_cache">true</property>

<!-- disabled on live env -->
<property name="show_sql">false</property>
...

--------------------------

...
<cache usage="read-write" include="non-lazy" />

<id name="id" type="long" column="UNIQUE_ID">
<generator class="sequence">
<param name="sequence">CRUK.CRUK_AJT_SEQ</param>
</generator>
</id>

<property name="groupId" column="GROUP_ID"/>
<property name="titleOrOther" column="TITLE"/>
<property name="firstName" column="FIRST_NAME"/>
...


Code between sessionFactory.openSession() and session.close():



SESSION 1 - INSERT PERSON

Person p = new Person();
// setting propertirs here...

Session sessionHib = HibernateUtil.currentSession();
try
{
sessionHib.beginTransaction();
sessionHib.save(p);
sessionHib.getTransaction().commit();
}
catch (RuntimeException ex)
{
sessionHib.getTransaction().rollback();
}


PERSON GOES TO WORLD PAY PAYMENT SYSTEM


SESSION 2 - SHOULD UPDATE USER.
Session sessionHib = HibernateUtil.currentSession();
try
{
sessionHib.beginTransaction();
applicant = (Person)sessionHib.load(Person.class, Long.valueOf(applicantId));
applicant.setWorldPayId(worldPayId);
applicant.setCompletedForm("Y");
// use the same session to get the highest running ID
applicant.setRunningId(Long.valueOf(Person.getNewRunningId(sessionHib, applicant.getVenue(), request)));
sessionHib.update(applicant);
sessionHib.getTransaction().commit();
}
catch (RuntimeException ex)
{
sessionHib.getTransaction().rollback();
}




public static String getNewRunningId(Session sessionHib, String venueId, HttpServletRequest request)
{
Log log1 = LogFactory.getFactory().getInstance(Person.class);

Long max = null;
try
{
MessageResources messages = (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);
max = (Long)sessionHib.createSQLQuery(messages.getMessage("form.entry.sql.getMaxRunningIdForVenue"))
.addScalar("maxRunId", Hibernate.LONG).
setString("venueId", venueId).
uniqueResult();
}
catch(Exception e)
{
log1.info("Error getting new ID: " + e.getMessage());
}
/*
* Running ID should not be lower than 10
* */
log1.debug("HELLO AGAIN FROM new running id.");
return (max==null || ( max!=null && Integer.parseInt(max.toString())<11)) ? "11" : max.toString();
}



Full stack trace of any exception that occurs:

No errors reported

Name and version of the database you are using:

Oracle9i Enterprise Edition Release 9.0.1.3.0 - Production

The generated SQL (show_sql=true):

Not available - live server

Debug level Hibernate log excerpt:

---------------------


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 4:00 pm 
Newbie

Joined: Fri Jun 30, 2006 5:30 pm
Posts: 13
From your code, it doesn't look like you need to call update. You already have an attached instance of Person. Granted, it shouldn't create a new one, but it doesn't look like that call is necessary.

Is the 2nd part of that xml the config for Person? Maybe try posting the full XML, and post the equals() method on Person.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.