-->
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.  [ 1 post ] 
Author Message
 Post subject: Sporadic inconsistence across threads
PostPosted: Sun Mar 15, 2009 11:22 pm 
Newbie

Joined: Sun Mar 15, 2009 10:32 pm
Posts: 1
There is a many-to-one relationship PlacedBets => Position. One longer-running thread reads PlacedBets and sometimes updates them. New PlacedBets are inserted by dedicated threads. No PlacedBet is ever deleted.

Almost always it works as expected, and the newly inserted PlacedBets show up immediately in the longer-running thread. But once in a while, a PlacedBet somehow gets stuck, and it takes a few iterations until it shows up.

To trace this problem, I use the same code in both places to fetch and display the PlacedBets, which results in the same SQL query being sent to the database - see below. I always use a fresh session only for this purpose. In the threads that insert PlacedBets, I do this immediately after every insert.

Second level cache and query cache are turned off.

I have tried to reproduce this with stripped-down test code, but couldn't, so there could be something wrong with my mapping.

If you could point me in the right direction I would be immensely grateful.

Hibernate version:
3.3.1
Mapping documents:
Position.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
    <class
        name="biz.bet.mm.model.Position"
        table="position"
    >

        <id
            name="positionId"
            column="positionId"
            type="int"
            unsaved-value="any"
        >
            <generator class="identity">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-Position.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <bag
            name="placedBets"
            table="placedbet"
            lazy="true"
            inverse="true"
            cascade="all"
        >

            <key
                column="positionId"
            >
            </key>

            <one-to-many
                  class="biz.bet.mm.model.PlacedBet"
            />

      </bag>

        <many-to-one
            name="marketData"
            class="biz.bet.mm.model.MarketData"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="marketId"
            not-null="true"
        />

        <property
            name="createdTime"
            type="java.util.Date"
            update="true"
            insert="true"
            column="createdTime"
        />

        <property
            name="rule"
            type="java.lang.String"
            update="true"
            insert="true"
            column="rule"
        />

        <property
            name="open"
            type="boolean"
            update="true"
            insert="true"
            column="open"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Position.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>

PlacedBet.hbm.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
    <class
        name="biz.bet.mm.model.PlacedBet"
        table="placedbet"
    >

        <id
            name="betId"
            column="betId"
            type="long"
        >
            <generator class="assigned">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-PlacedBet.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <property
            name="marketId"
            type="int"
            update="true"
            insert="true"
            column="marketId"
        />

        <property
            name="price"
            type="double"
            update="true"
            insert="true"
            column="price"
        />

        <property
            name="selectionId"
            type="int"
            update="true"
            insert="true"
            column="selectionId"
        />

        <property
            name="size"
            type="double"
            update="true"
            insert="true"
            column="size"
        />

        <property
            name="asianLineId"
            type="int"
            update="true"
            insert="true"
            column="asianLineId"
        />

        <property
            name="betCategoryType"
            type="java.lang.String"
            update="true"
            insert="true"
            column="betCategoryType"
        />

        <property
            name="betPersistenceType"
            type="java.lang.String"
            update="true"
            insert="true"
            column="betPersistenceType"
        />

        <property
            name="betType"
            type="java.lang.String"
            update="true"
            insert="true"
            column="betType"
        />

        <property
            name="bspLiability"
            type="double"
            update="true"
            insert="true"
            column="bspLiability"
        />

        <many-to-one
            name="position"
            class="biz.bet.mm.model.Position"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="positionId"
            not-null="false"
        />

        <property
            name="sizeMatched"
            type="double"
            update="true"
            insert="true"
            column="sizeMatched"
        />

        <property
            name="potentialProfit"
            type="double"
            update="true"
            insert="true"
            column="potentialProfit"
        />

        <property
            name="sizeUnmatched"
            type="double"
            update="true"
            insert="true"
            column="sizeUnmatched"
        />

        <property
            name="updateTime"
            type="java.util.Date"
            update="true"
            insert="true"
            column="updateTime"
        />

        <property
            name="placeTime"
            type="java.util.Date"
            update="true"
            insert="true"
            column="placeTime"
        />

        <property
            name="closeTime"
            type="java.util.Date"
            update="true"
            insert="true"
            column="closeTime"
        />

        <property
            name="persistent"
            type="boolean"
            update="true"
            insert="true"
            column="persistent"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-PlacedBet.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
(List<PlacedBet>)testPlacedBets = (List<PlacedBet>)session.createQuery(String.format("from PlacedBet as placedbet where positionId = %d", myPos.getPositionId())).list();
System.out.println(String.format("*** DEBUG PLACEDBETS: %d ***", System.currentTimeMillis()));
System.out.println(testPlacedBets);

Name and version of the database you are using:
MySQL 5.0.51a-24

The generated SQL (show_sql=true):
Code:
select placedbet0_.betId as betId7_, placedbet0_.marketId as marketId
7_, placedbet0_.price as price7_, placedbet0_.selectionId as selectio4_7_, placedbet0_.size as size7_, placedbet0_.asianLineId as asianLin6_7_, placedbet0_.betCategoryType as betCateg7_7_, placedbet0_.betPersistenceType as betPersi8_7_, placedbet0_.betType as betType7_, placedbet0_.bspLiability as bspLiab10_7_, placedbet0_.positionId as positionId7_, placedbet0_.sizeMatched as sizeMat12_7_, placedbet0_.potentialProfit as potenti13_7_, placedbet0_.sizeUnmatched as sizeUnm14_7_, placedbet0_.updateTime as updateTime7_, placedbet0_.placeTime as placeTime7_,
placedbet0_.closeTime as closeTime7_, placedbet0_.persistent as persistent7_ from placedbet placedbet0_ where positionId=67


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

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.