-->
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.  [ 5 posts ] 
Author Message
 Post subject: Update instead of Insert
PostPosted: Wed Sep 20, 2006 7:51 am 
Newbie

Joined: Wed Mar 22, 2006 5:40 pm
Posts: 4
I'm using Spring and Hibernate. I'm calling getHibernateTemplate().saveOrUpdate(o) on an object that has not been persisted and does not exist in the db. When the transaction commits, Hibernate generates an update statement instead of an insert.

What configs control this? Is there something special I need to do? This is the first time I've come across this. I haven't had any issues with any other objects.

Here is my general config info:

Hibernate version: 3.2.0.cr1 with Spring 1.2.7

Mapping documents:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class mutable="true" proxy="com.fxall.admin.domain.entity.SenderCompID" table="SENDERCOMPIDS" name="com.fxall.admin.domain.entity.SenderCompID">
<id column="SENDERCOMPID" name="senderCompID">
<generator class="native"/>
</id>
<property name="password" not-null="true" column="PASSWORD"/>
<property name="ownerID" not-null="true" column="OWNER_PARTICIPANT_ID"/>
<property name="userGroupID" column="UG_PARTICIPANT_ID"/>
<property name="deleted" type="yes_no" column="DELETED_FLAG"/>
<property name="deletedDate" column="DELETED_FLAG_CHANGE_DATE"/>
<property name="createdBy" column="CREATED_BY"/>
<property name="createdOn" column="CREATED_DATE"/>
<property name="modifiedBy" column="MODIFIED_BY"/>
<property name="modifiedOn" column="MODIFIED_DATE"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
getHibernateTemplate().saveOrUpdate(o)

Name and version of the database you are using: Oracle 9i


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 11:09 am 
Newbie

Joined: Wed Mar 22, 2006 5:40 pm
Posts: 4
Below is the log output. It seems that my object is being treated as a Detached Object, but it should be considered in the Transient state from what I've read. I created the object myself in the UI Tier.

Here is the log output:

2006-09-21 10:58:54,203 DEBUG com.fxall.admin.dao.entity.hibernate.EntityDAOHibernate - saveSenderCompID::begin
2006-09-21 10:58:54,218 DEBUG org.hibernate.engine.IdentifierValue - id unsaved-value: null
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractSaveEventListener - detached instance of: com.fxall.admin.domain.entity.SenderCompID
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - updating detached instance
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - updating [com.fxall.admin.domain.entity.SenderCompID#frank_mp_cust-ord-1]
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - updating [com.fxall.admin.domain.entity.SenderCompID#frank_mp_cust-ord-1]
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - flushing session
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - processing flush-time cascades
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - dirty checking collections
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushing entities and processing referenced collections
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.DefaultFlushEntityEventListener - Updating entity: [com.fxall.admin.domain.entity.Customer#161]
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.DefaultFlushEntityEventListener - Updating entity: [com.fxall.admin.domain.entity.SenderCompID#frank_mp_cust-ord-1]
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Processing unreferenced collections
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Scheduling collection removes/(re)creates/updates
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 0 insertions, 2 updates, 0 deletions to 2 objects
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2006-09-21 10:58:54,218 DEBUG org.hibernate.pretty.Printer - listing entities:
2006-09-21 10:58:54,218 DEBUG org.hibernate.pretty.Printer - com.fxall.admin.domain.entity.Customer{modifiedBy=admin.cic, matchInternalOrder=null, modifiedOn=2006-09-21 10:58:56, privateMP=false, cancelOrdersOnDisconnect=null, enableMPClient=false, createdBy=null, providerName=null, userGroupName=null, participantID=161, markAllTradesPTA=null, commissionUSDPerMillion=2.2, applyPriceImprovement=null, commissionMinimumRate=1.1, userGroupOwner=null, customerName=frank_mp_cust, matchStreamOrder=null, allowedLiquidityManagement=false, contingentOrderSupplier=true, allowedContingentOrderProtection=false, participantName=frank_mp_cust, createdOn=null}
2006-09-21 10:58:54,218 DEBUG org.hibernate.pretty.Printer - com.fxall.admin.domain.entity.SenderCompID{deleted=false, password=745021f1d81c9a2b25a27f060bf72e7bbf0021ef, senderCompID=frank_mp_cust-ord-1, modifiedBy=null, modifiedOn=null, userGroupID=null, ownerID=161, createdBy=admin.cic, deletedDate=null, createdOn=2006-09-21 10:58:56}
2006-09-21 10:58:54,218 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - executing flush
2006-09-21 10:58:54,218 DEBUG org.hibernate.jdbc.ConnectionManager - registering flush begin
2006-09-21 10:58:54,218 DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Updating entity: [com.fxall.admin.domain.entity.Customer#161]
2006-09-21 10:58:54,218 DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement(open PreparedStatements: 0, globally: 0)
2006-09-21 10:58:54,218 DEBUG org.hibernate.SQL - update PARTICIPANTS set PARTICIPANT_NAME=?, CUSTOMER_NAME=?, PROVIDER_NAME=?, USER_GROUP_NAME=?, UG_OWNER=?, PRIVATE_MP_FLAG=?, CONT_ORD_SUPPLIER_FLAG=?, ALLOW_CON_ORD_PROTECT_FLAG=?, ALLOW_LIQUIDITY_MGMT_FLAG=?, MARK_ALL_TRADES_PTA_FLAG=?, MATCH_STREAM_ORD_FLAG=?, MATCH_INTERNAL_ORD_FLAG=?, APPLY_PRICE_IMPROVEMENT_FLAG=?, CANCEL_ORDERS_ON_DISCO_FLAG=?, ENABLE_MP_CLIENT_FLAG=?, COMM_USD_PER_MILLION=?, COMM_MINIMUM_RATE=?, CREATED_BY=?, CREATED_DATE=?, MODIFIED_BY=?, MODIFIED_DATE=? where PARTICIPANT_ID=?
2006-09-21 10:58:54,218 DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
2006-09-21 10:58:54,218 DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [com.fxall.admin.domain.entity.Customer#161]
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.StringType - binding 'frank_mp_cust' to parameter: 1
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.StringType - binding 'frank_mp_cust' to parameter: 2
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.StringType - binding null to parameter: 3
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.StringType - binding null to parameter: 4
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.LongType - binding null to parameter: 5
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding 'false' to parameter: 6
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding 'true' to parameter: 7
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding 'false' to parameter: 8
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding 'false' to parameter: 9
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding null to parameter: 10
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding null to parameter: 11
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding null to parameter: 12
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding null to parameter: 13
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding null to parameter: 14
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.YesNoType - binding 'false' to parameter: 15
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.BigDecimalType - binding '2.2' to parameter: 16
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.BigDecimalType - binding '1.1' to parameter: 17
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.StringType - binding null to parameter: 18
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.TimestampType - binding null to parameter: 19
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.StringType - binding 'admin.cic' to parameter: 20
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.TimestampType - binding '2006-09-21 10:58:56' to parameter: 21
2006-09-21 10:58:54,218 DEBUG org.hibernate.type.LongType - binding '161' to parameter: 22
2006-09-21 10:58:54,218 DEBUG org.hibernate.jdbc.AbstractBatcher - Adding to batch
2006-09-21 10:58:54,218 DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Updating entity: [com.fxall.admin.domain.entity.SenderCompID#frank_mp_cust-ord-1]
2006-09-21 10:58:54,218 DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 1
2006-09-21 10:58:54,421 DEBUG org.hibernate.jdbc.AbstractBatcher - success of batch update unknown: 0
2006-09-21 10:58:54,421 DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-09-21 10:58:54,421 DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
2006-09-21 10:58:54,437 DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement(open PreparedStatements: 0, globally: 0)
2006-09-21 10:58:54,437 DEBUG org.hibernate.SQL - update SENDERCOMPIDS set PASSWORD=?, OWNER_PARTICIPANT_ID=?, UG_PARTICIPANT_ID=?, DELETED_FLAG=?, DELETED_FLAG_CHANGE_DATE=?, CREATED_BY=?, CREATED_DATE=?, MODIFIED_BY=?, MODIFIED_DATE=? where SENDERCOMPID=?
2006-09-21 10:58:54,437 DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
2006-09-21 10:58:54,437 DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [com.fxall.admin.domain.entity.SenderCompID#frank_mp_cust-ord-1]
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.StringType - binding '745021f1d81c9a2b25a27f060bf72e7bbf0021ef' to parameter: 1
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.LongType - binding '161' to parameter: 2
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.LongType - binding null to parameter: 3
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.YesNoType - binding 'false' to parameter: 4
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.TimestampType - binding null to parameter: 5
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.StringType - binding 'admin.cic' to parameter: 6
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.TimestampType - binding '2006-09-21 10:58:56' to parameter: 7
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.StringType - binding null to parameter: 8
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.TimestampType - binding null to parameter: 9
2006-09-21 10:58:54,437 DEBUG org.hibernate.type.StringType - binding 'frank_mp_cust-ord-1' to parameter: 10
2006-09-21 10:58:54,437 DEBUG org.hibernate.jdbc.AbstractBatcher - Adding to batch
2006-09-21 10:58:54,437 DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 1
2006-09-21 10:58:54,515 DEBUG org.hibernate.jdbc.AbstractBatcher - success of batch update unknown: 0
2006-09-21 10:58:54,515 DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-09-21 10:58:54,515 DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
2006-09-21 10:58:54,546 DEBUG org.hibernate.jdbc.ConnectionManager - registering flush end
2006-09-21 10:58:54,546 DEBUG org.hibernate.event.def.AbstractFlushingEventListener - post flush
2006-09-21 10:58:54,546 DEBUG org.hibernate.impl.SessionImpl - closing session
2006-09-21 10:58:54,546 DEBUG org.hibernate.jdbc.ConnectionManager - performing cleanup
2006-09-21 10:58:54,546 DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2006-09-21 10:58:54,671 DEBUG org.hibernate.jdbc.JDBCContext - after transaction completion


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 12:56 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
What does your SenderCompID class look like? Is the 'id' null when you call saveOrUpdate()?

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 1:01 pm 
Newbie

Joined: Wed Mar 22, 2006 5:40 pm
Posts: 4
No. It's a value assigned by the user. I have my generator class set to native. That may be the problem. I'm checking now what the other options are.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 1:04 pm 
Newbie

Joined: Wed Mar 22, 2006 5:40 pm
Posts: 4
That was it. The generator class needs to be assigned.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.