Hi,
when loading an Object with lock mode UPGRADE, the database does not lock the row.
When searching for the problem, we detected that the generated SQL Query contains the wrong from clause:
instead of from campaign it should be from campaign with (updlock, rowlock).
We assume that the method Select.toStatementString is wrong: instead of
buf.append("select ").append(selectClause) .append(" from ").append(fromClause);
it should integrate the lock clause as for example is done in the method SimpleSelect.toStatementString:
buf.append(" from ") .append( dialect.appendLockHint(lockMode, tableName) );
Please, can you tell me, if this is a real bug or if we are using it the wrong way?
If it is a bug: is the solution as simple as supposed above?
Thank you in advance
Markus
Our code:
Campaign c = (Campaign) session.load(Campaign.class, new Long(1), LockMode.UPGRADE);
Hibernate version:
3.0.2
Mapping documents:
<hibernate-mapping>
<class table="Campaign" name="net.atrada.muppets.domain.Campaign">
<id unsaved-value="0" name="id" column="campaignid">
<generator class="identity"/>
</id>
<timestamp unsaved-value="null" name="lastChange" column="campaignlastchange"/>
<many-to-one column="campaignauthor" class="net.atrada.muppets.domain.Member" lazy="true" name="author"/>
<property name="cashTime" column="campaigncashtime"/>
<property name="code" column="campaigncode"/>
<property name="end" column="campaignend"/>
<property name="event" column="campaignevent"/>
<property name="lastUpdate" column="campaignlastupdate"/>
<property name="lowerLimit" column="campaignlowerlimit" type="net.atrada.muppets.persistence.hibernate.usertype.MoneyUserType"/>
<property name="name" column="campaignname"/>
<property name="quantity" column="campaignquantity"/>
<property name="start" column="campaignstart"/>
<property name="type" column="campaignvouchertype" type="net.atrada.muppets.persistence.hibernate.usertype.VoucherTypeUserType"/>
<property name="value" column="campaignvalue" type="net.atrada.muppets.persistence.hibernate.usertype.MoneyUserType"/>
<one-to-one name="eventVoucher" lazy="true" class="net.atrada.muppets.domain.EventVoucher" property-ref="campaign" cascade="all"/>
<set inverse="true" cascade="all" lazy="true" name="vouchers">
<key column="vouchercampaignid"/>
<one-to-many class="net.atrada.muppets.domain.Voucher"/>
</set>
<property name="activateDate" column="campaignactivatedat"/>
<property name="createDate" column="campaigncreatedat"/>
<property name="pauseDate" column="campaignpausedat"/>
<property name="generatedVouchers" column="campaigngeneratedvouchers"/>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
no exception
Name and version of the database you are using:
MS SQL Server 8.0
org.hibernate.dialect.SQLServerDialect
The generated SQL (show_sql=true):
13.07.2005 21:30:27 DEBUG org.hibernate.SQL: select campaign0_.campaignid as campaignid0_, campaign0_.campaignlastchange as campaign2_74_0_, campaign0_.campaignauthor as campaign3_74_0_, campaign0_.campaigncashtime as campaign4_74_0_, campaign0_.campaigncode as campaign5_74_0_, campaign0_.campaignend as campaign6_74_0_, campaign0_.campaignevent as campaign7_74_0_, campaign0_.campaignlastupdate as campaign8_74_0_, campaign0_.campaignlowerlimit as campaign9_74_0_, campaign0_.campaignname as campaig10_74_0_, campaign0_.campaignquantity as campaig11_74_0_, campaign0_.campaignstart as campaig12_74_0_, campaign0_.campaignvouchertype as campaig13_74_0_, campaign0_.campaignvalue as campaig14_74_0_, campaign0_.campaignactivatedat as campaig15_74_0_, campaign0_.campaigncreatedat as campaig16_74_0_, campaign0_.campaignpausedat as campaig17_74_0_, campaign0_.campaigngeneratedvouchers as campaig18_74_0_ from Campaign campaign0_ where campaign0_.campaignid=?
Debug level Hibernate log excerpt:
13.07.2005 21:30:27 DEBUG org.hibernate.event.def.DefaultLoadEventListener: attempting to resolve: [net.atrada.muppets.domain.Campaign#1]
13.07.2005 21:30:27 DEBUG org.hibernate.event.def.DefaultLoadEventListener: object not resolved in any cache: [net.atrada.muppets.domain.Campaign#1]
13.07.2005 21:30:27 DEBUG org.hibernate.persister.entity.BasicEntityPersister: Materializing entity: [net.atrada.muppets.domain.Campaign#1]
13.07.2005 21:30:27 DEBUG org.hibernate.loader.Loader: loading entity: [net.atrada.muppets.domain.Campaign#1]
13.07.2005 21:30:27 DEBUG org.hibernate.jdbc.AbstractBatcher: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
13.07.2005 21:30:27 DEBUG org.hibernate.SQL: select campaign0_.campaignid as campaignid0_, campaign0_.campaignlastchange as campaign2_74_0_, campaign0_.campaignauthor as campaign3_74_0_, campaign0_.campaigncashtime as campaign4_74_0_, campaign0_.campaigncode as campaign5_74_0_, campaign0_.campaignend as campaign6_74_0_, campaign0_.campaignevent as campaign7_74_0_, campaign0_.campaignlastupdate as campaign8_74_0_, campaign0_.campaignlowerlimit as campaign9_74_0_, campaign0_.campaignname as campaig10_74_0_, campaign0_.campaignquantity as campaig11_74_0_, campaign0_.campaignstart as campaig12_74_0_, campaign0_.campaignvouchertype as campaig13_74_0_, campaign0_.campaignvalue as campaig14_74_0_, campaign0_.campaignactivatedat as campaig15_74_0_, campaign0_.campaigncreatedat as campaig16_74_0_, campaign0_.campaignpausedat as campaig17_74_0_, campaign0_.campaigngeneratedvouchers as campaig18_74_0_ from Campaign campaign0_ where campaign0_.campaignid=?
13.07.2005 21:30:27 DEBUG org.hibernate.jdbc.AbstractBatcher: preparing statement
13.07.2005 21:30:27 DEBUG org.hibernate.type.LongType: binding '1' to parameter: 1
13.07.2005 21:30:30 DEBUG org.hibernate.jdbc.AbstractBatcher: about to open ResultSet (open ResultSets: 0, globally: 0)
13.07.2005 21:30:30 DEBUG org.hibernate.loader.Loader: processing result set
13.07.2005 21:30:30 DEBUG org.hibernate.loader.Loader: result set row: 0
13.07.2005 21:30:30 DEBUG org.hibernate.loader.Loader: result row: EntityKey[net.atrada.muppets.domain.Campaign#1]
13.07.2005 21:30:30 DEBUG org.hibernate.loader.Loader: Initializing object from ResultSet: [net.atrada.muppets.domain.Campaign#1]
13.07.2005 21:30:30 DEBUG org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [net.atrada.muppets.domain.Campaign#1]
|