-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate timestamping checking
PostPosted: Mon Aug 03, 2009 11:27 pm 
Newbie

Joined: Mon Aug 03, 2009 11:12 pm
Posts: 5
Hello guys,

Ok, ill rephrase my entire post. hehe
i am working on a project which involve intensive monetary transactions,
thus i really need to secure each transaction.
I want to perform a record locking and timestamping on each transaction.

for instance, user1 and user2 access a single record at the same time.
then, user1 saves his changes. While user1's transaction (of saving his changes)
is on going, i would like that record to be locked.
once the transaction is done (the changes are committed to the database) and the timestamp
is updated for that record (timestamp is done via triggers and is done before insert), the changes now
will be available to user2 and thus, since there are changes on the timestamp, he can not proceed to his transaction.

how can i set the locking up on hibernate.

here is my hibernate.cfg.xml

Code:
<session-factory>
        <property name="connection.username">root</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/employee</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="myeclipse.connection.profile">MySQL</property>
        <property name="connection.password">root</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.autocommit">true</property>
       
        <!-- Connection Pooling config, using cp30 -->
        <property name="hibernate.c3p0.max_size">1</property>
        <property name="hibernate.c3p0.min_size">1</property>
        <property name="hibernate.c3p0.timeout">5000</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.c3p0.acquire_increment">3</property>
        <property name="hibernate.c3p0.idle_test_period">300</property>
       
        <mapping class="com.xxx.model.User" />
        <mapping class="com.xxx.model.Role" />
    </session-factory>


and here is my applicationContext.xml

Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="configLocation" value="classpath:hibernate_employee.cfg.xml" />
   </bean>

<bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="transactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

<bean class="com.goldenway.action.UserAction" id="UserAction" scope="prototype" >
       <property name="manager" ref="manager"/>
       <property name="userManager" ref="userManager" />
    </bean>


please advise....

i have tried using hibernate before, but i have not tried setting it up. usually, my seniors are the one to set the hibernate environment up.
and now, this is my first time doing it myself. please go easy on me. thanks

marckun

*note above codes are mock examples.


Top
 Profile  
 
 Post subject: Re: Hibernate timestamping checking
PostPosted: Thu Aug 06, 2009 5:37 am 
Newbie

Joined: Mon Aug 03, 2009 11:12 pm
Posts: 5
any feedback guys will be much appreciated. thanks


Top
 Profile  
 
 Post subject: Re: Hibernate timestamping checking
PostPosted: Thu Aug 06, 2009 5:56 am 
Beginner
Beginner

Joined: Wed Jul 29, 2009 3:43 pm
Posts: 22
As long as you don't care who started his transaction first and just want to isolate the two transactions so that one user can not overwrite the changes made by the other user, you can use optimistic locking , which requires you a define a column in your table as the version column.

In case you actually want the table rows to be locked whilst a transaction is in progress , you can go for pessimistic locking.


Top
 Profile  
 
 Post subject: Re: Hibernate timestamping checking
PostPosted: Fri Aug 07, 2009 5:12 am 
Newbie

Joined: Mon Aug 03, 2009 11:12 pm
Posts: 5
JimJB wrote:
As long as you don't care who started his transaction first and just want to isolate the two transactions so that one user can not overwrite the changes made by the other user, you can use optimistic locking , which requires you a define a column in your table as the version column.

In case you actually want the table rows to be locked whilst a transaction is in progress , you can go for pessimistic locking.



just a question though..will timestamping be enough to do this.. like i wont lock the record and just update the timestamp or version of the record whenever an update has been issued..... coz everytime i told people about locking the record, they also frowned my approach. hehehe im a rookie guys so im a little new in this..

pls advise

-marckun


Top
 Profile  
 
 Post subject: Re: Hibernate timestamping checking
PostPosted: Fri Aug 07, 2009 5:20 am 
Beginner
Beginner

Joined: Wed Jul 29, 2009 3:43 pm
Posts: 22
Yes you can use timestamp as well but IMO it's better to use the version column. You would not need to manually update the version column , it will automatically be done for you when you do any updates.


Top
 Profile  
 
 Post subject: Re: Hibernate timestamping checking
PostPosted: Fri Aug 07, 2009 9:30 pm 
Newbie

Joined: Mon Aug 03, 2009 11:12 pm
Posts: 5
JimJB wrote:
Yes you can use timestamp as well but IMO it's better to use the version column. You would not need to manually update the version column , it will automatically be done for you when you do any updates.


thank you very much for the adivse..

but when you said "...., it [updating of version column] will automatically be done for you when you do any updates." you mean to say i dont have to use any trigger? hibernate will do that!?.. hmmmm that's convinient..

thanks man,
-marckun


Top
 Profile  
 
 Post subject: Re: Hibernate timestamping checking
PostPosted: Sat Aug 08, 2009 4:24 am 
Beginner
Beginner

Joined: Wed Jul 29, 2009 3:43 pm
Posts: 22
Yes, that's right. The version/Timestamp column is automatically updated for you.


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