-->
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: Locking related table when loading
PostPosted: Wed Dec 31, 2008 2:41 am 
Newbie

Joined: Wed Dec 31, 2008 2:25 am
Posts: 1
Hi,
this is my first post on this forum, have been reading for some months now.

An entity of mine is called "ShoppingRound", and that entity has a relation to another one called "ShoppingDetails". It looks like this:

Code:
@Entity
@Table(name="shop_round")
public class ShoppingRound extends HibernateEntity<ShoppingRound> {
   
   
    @Column(name="shopping_time", nullable = false)
    private long shoppingTime;
...
...
...
...
    /**
     * The <code>ShoppingDetails</code>s of this <code>ShoppingRound</code>.
     */
    @OneToOne(mappedBy="shop_round", fetch=FetchType.LAZY)
    @OnDelete(action = OnDeleteAction.CASCADE)
    private ShoppingDetails shopDetails;
...
...
...



At one point I load a ShoppingRound

Code:
ShoppingRound shopRound = (ShoppingRound) session.get(ShoppingRound.class, this.shopId);


The problem is that when trying to load the ShoppingRound
I get the following exception:

Code:
org.hibernate.exception.GenericJDBCException: could not load an entity: [mypackage.ShoppingDetails#1]


Complete stack trace below.
So, it seems like Hibernate is trying to get a lock on a table related to ShoppingRound, although no data from that table is manipulated.
Is this normal Hibernate-behaviour? If so, any suggestions on how I can go around it?

Hibernate version: 3.3.1

Full stack trace of any exception that occurs:

org.hibernate.exception.GenericJDBCException: could not load an entity: [mypackage.ShoppingDetails#1]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1895)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:108)
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1672)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:641)
at org.hibernate.type.EntityType.resolve(EntityType.java:415)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
at org.hibernate.loader.Loader.doQuery(Loader.java:752)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3072)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:121)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:863)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:95)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at mypackage.ShopRound_$$_javassist_30.setShoppingTime(ShopRound_$$_javassist_30.java)
at mypackage.ShopHandling.setShoppingTime(ShopHandling.java:1040)
at mypackage.shop.run(ShopExecutor.java:153)
Caused by: org.h2.jdbc.JdbcSQLException: Timeout trying to lock table SHOP_DETAILS; SQL statement:
select shopdetail0_.id as id28_0_, shopdetail0_.store as store28_0_, shopdetail0_.manager_name as manager3_28_0_, shopdetail0_.discount as discount28_0_, shopdetail0_.discount_name as discount5_28_0_, shopdetail0_.area_name as area6_28_0_, shopdetail0_.shopround_id as shopround9_28_0_, shopdetail0_.shopper_name as shopper7_28_0_, shopdetail0_.shopping_type as shoppingtype8_28_0_, shopdetail0_.user_id as user10_28_0_ from shop_details shopdetail0_ where shopdetail0_.shopround_id=? [50200-79]
at org.h2.message.Message.getSQLException(Message.java:103)
at org.h2.message.Message.getSQLException(Message.java:114)
at org.h2.message.Message.getSQLException(Message.java:77)
at org.h2.table.TableData.doLock(TableData.java:412)
at org.h2.table.TableData.lock(TableData.java:351)
at org.h2.table.TableFilter.lock(TableFilter.java:106)
at org.h2.command.dml.Select.queryWithoutCache(Select.java:535)
at org.h2.command.dml.Query.query(Query.java:233)
at org.h2.command.CommandContainer.query(CommandContainer.java:79)
at org.h2.command.Command.executeQueryLocal(Command.java:140)
at org.h2.command.Command.executeQuery(Command.java:121)
at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:96)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 31, 2008 5:30 am 
Beginner
Beginner

Joined: Wed Nov 26, 2008 1:02 am
Posts: 22
hi,
you are using h2 database,for this database default locking is table level locking(not row level),acquiring table lock is causing time out exception so append MVCC=TRUE to database url.and check,

hope this solves your problem

regards,


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.