-->
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: Hibernate Concurrent problem....???
PostPosted: Mon Apr 18, 2005 10:23 pm 
Newbie

Joined: Fri Aug 20, 2004 11:48 am
Posts: 7
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.8

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.mobileserver.Player" table="player" lazy="true">
<id name="playerID" column="playerid" type="long" length="12">
<generator class="native"/>
</id>
<property name="name" column="name" type="string" length="30" not-null="true"/>
<property name="phoneNo" column="phoneno" type="string" length="12" not-null="true"/>
<property name="type" column="type" type="string" length="1" not-null="true"/>
<property name="joinDate" column="joindate" type="timestamp" length="19" not-null="true"/>
<property name="password" column="password" type="string" length="15" not-null="true"/>
<property name="emailAddress" column="emailaddress" type="string" length="60" not-null="true"/>
<property name="startBalance" column="startbalance" type="long" length="12" not-null="true"/>
<property name="creditPoint" column="creditpoint" type="long" length="12" not-null="true"/>
</class>
</hibernate-mapping>


player table structure:
DROP TABLE IF EXISTS `player`;
CREATE TABLE `player` (
`PlayerID` int(12) NOT NULL auto_increment,
`Name` varchar(30) NOT NULL default '',
`PhoneNo` varchar(12) NOT NULL default '0',
`Type` varchar(2) NOT NULL default '',
`JoinDate` datetime NOT NULL default '0000-00-00 00:00:00',
`Password` varchar(15) NOT NULL default 'password',
`EmailAddress` varchar(60) NOT NULL default '',
`StartBalance` int(12) NOT NULL default '0',
`CreditPoint` bigint(12) NOT NULL default '0',
`OperatorID` int(2) NOT NULL default '0',
`LoginID` varchar(10) NOT NULL default '',
PRIMARY KEY (`PlayerID`),
UNIQUE KEY `EmailAddress` (`EmailAddress`),
UNIQUE KEY `LoginID` (`LoginID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


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

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();

List playerList = session.find("from Player where playerid = 1");
Player player = (Player) playerList.get(0);
System.out.println("Player 's CreditPoint: " + player.getCreditPoint());

playerList = session.find("from Player where playerid = 1");
player = (Player) playerList.get(0);
System.out.println("Player 's CreditPoint: " + player.getCreditPoint());

playerList = session.find("from Player where playerid = 2");
player = (Player) playerList.get(0);
System.out.println("Player 's CreditPoint: " + player.getCreditPoint());

session.close();



<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mmgame?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">mmgame</property>
<property name="hibernate.connection.password">mmgame</property>

<!-- configuration pool via c3p0-->
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<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> <!-- seconds -->
<!-- DEPRECATED very expensive property name="c3p0.validate>-->

<!-- Mapping files -->
<mapping resource="Player.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Name and version of the database you are using: mysql 4.1.10a-nt
JDBC driver: mysql-connector-java-3.1.7-bin.jar
Connection Pool: c3p0-0.9.0-pre2.jar

The generated SQL (show_sql=true):
The Orginal credit point for player 1 and player2 is 999999;

While I change player 1 's credit point to 8888 in Database between sessionFactory.openSession() and the find session.find();

Now output is:
Hibernate: select player0_.playerid as playerid, player0_.name as name, player0_.phoneno as phoneno, player0_.type as type, player0_.joindate as joindate, player0_.password as password, player0_.emailaddress as emailadd7_, player0_.startbalance as startbal8_, player0_.creditpoint as creditpo9_, player0_.operatorid as operatorid from player player0_ where (playerid=1 )
Player 's CreditPoint: 8888

Secondly, I try to change player 1 's credit point again, Now I change it to 7777. Before the second session.find() statement;

Now output is:
Hibernate: select player0_.playerid as playerid, player0_.name as name, player0_.phoneno as phoneno, player0_.type as type, player0_.joindate as joindate, player0_.password as password, player0_.emailaddress as emailadd7_, player0_.startbalance as startbal8_, player0_.creditpoint as creditpo9_, player0_.operatorid as operatorid from player player0_ where (playerid=1 )
Player 's CreditPoint: 8888

No change to the output???????


The third statement I try to change another player 's credit point to 22222 (Player2). Before the third session.find() statement;

No effect of the session.find()????????

Hibernate: select player0_.playerid as playerid, player0_.name as name, player0_.phoneno as phoneno, player0_.type as type, player0_.joindate as joindate, player0_.password as password, player0_.emailaddress as emailadd7_, player0_.startbalance as startbal8_, player0_.creditpoint as creditpo9_, player0_.operatorid as operatorid from player player0_ where (playerid=2 )
Player 's CreditPoint: 999999



After I read Hibernate in action this book 's charper 7.6.3 Caching queries <hibernate.cache.use_query_cache> By default is set to false, so that mean if I use the session.find() it would not keep the cache...


Would anybody tell me why the session.find() won't work after the first call?


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.