-->
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: Why sometimes the Transaction is required for Query
PostPosted: Fri Feb 23, 2007 1:59 pm 
Newbie

Joined: Tue Feb 24, 2004 11:35 am
Posts: 9
Location: Sofia, Bulgaria
Why sometimes the transaction is required for query, sometimes the transaction is not required?
Where and what is the logic for that?
In my opinion the transaction is not required for any query, but today I use Oracle 10g where was impossible to make Query without transaction:
public static List<Order> getOrders()
{
Session session = getSessionFactory().getCurrentSession();
Transaction transaction = session.beginTransaction();
try
{
List<Order> orders = (List<Order>)session.createQuery("from Order").list();
transaction.commit();
transaction.begin();
return orders;
}
catch(Throwable ex)
{
transaction.rollback();
session.close();
ex.printStackTrace();
throw new RuntimeException(ex);
}
}

I am looking in other projects which use MySQL and Derby where the transaction is not required for query.
Now I am trying to make the same situation for Derby but the query is processing fine without transaction.

Can somebody tell me where is the true and is it possible to configure Hibernate when use Oracle to make Query without using transactions?


Thank you in advance.


Miro.

_________________
Regards,
Miro


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 23, 2007 2:03 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://hibernate.org/42.html _AND ALL LINKED PAGES_.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 23, 2007 2:50 pm 
Newbie

Joined: Tue Feb 24, 2004 11:35 am
Posts: 9
Location: Sofia, Bulgaria
christian wrote:
http://hibernate.org/42.html _AND ALL LINKED PAGES_.


I read this few times and can not understand why the same code with Query one time can be executed without Transactaion, and for Oracle I need of transaction.

The transaction is OK for Update and Save, but for Query ???

_________________
Regards,
Miro


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 23, 2007 3:12 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Because you don't understand the auto-commit mode.

http://www.hibernate.org/403.html

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 4:08 am 
Newbie

Joined: Tue Feb 24, 2004 11:35 am
Posts: 9
Location: Sofia, Bulgaria
christian wrote:
Because you don't understand the auto-commit mode.

http://www.hibernate.org/403.html


I try to reproduce the problem using Derby database using AutoCommit with TRUE and FALSE values, but in both cases the Query works without BeginTransaction requirement.
Maybe I am stupid and need of more clarifucation. Could you be so kind to explain me why for Derby I do not need of Begin Transaction for any kind for query, but for Oracle I need?
Can I control this behaviour of Hibernate?

Just for your information I have your book (Dec-2006) and I can not find information for this case inside.

_________________
Regards,
Miro


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 12:04 pm 
Beginner
Beginner

Joined: Sat Dec 16, 2006 1:52 pm
Posts: 40
Why do you begin the transaction twice?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 12:12 pm 
Newbie

Joined: Tue Feb 24, 2004 11:35 am
Posts: 9
Location: Sofia, Bulgaria
dnoyeb wrote:
Why do you begin the transaction twice?


Forget for this example. These are some tests.
The right working examples are:

1. Orcale:
Session session = getSessionFactory().getCurrentSession();
Transaction transaction = session.beginTransaction();
session.createQuery("from Order").list();

2. Derby:
Session session = getSessionFactory().getCurrentSession();
session.createQuery("from Order").list();


When I try to make Oracle Query without transaction I have Hibernate Exception.

_________________
Regards,
Miro


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.