-->
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.  [ 3 posts ] 
Author Message
 Post subject: Named Query increments version number
PostPosted: Sun Jan 22, 2006 10:13 am 
Regular
Regular

Joined: Tue May 24, 2005 9:06 am
Posts: 64
Hibernate version: 3.1
Hibernate Annotations version: 3.1beta7
Database: PostgreSQL 8.1.2

In a read-only transaction I have just one Named Query with a fetch join. After invoking commit() the version number of the retrieved objects is incremented (not of the additionally fetched objects).

Is this result correct?

Is rollback() the only solution to prevent a read-only transaction from incrementing version numbers?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 6:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
not enough info

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 6:43 am 
Regular
Regular

Joined: Tue May 24, 2005 9:06 am
Posts: 64
The read-only transaction basically looks as follows, but increments the version number for optimistic synchronization:

Session s = HibernateUtil.getSession();
Transaction t = s.beginTransaction();
String lastname = "...";
Query q = s.getNamedQuery(CUST_BY_LASTNAME_FETCH_ORDERS);
q.setString("lastname", lastname);
q.setCacheable(true);
q.setCacheRegion("org.hibernate.cache.StandardQueryCache");
Collection<CustomerData> customers = query.list();
t.commit();

The POJO with the named query looks as follows:

@Entity(access=FIELD)
@Table(name="customer", schema="hska")
@Inheritance()
@DiscriminatorColumn(name="kind", length=1)
@NamedQueries({
CustomerData.CUST_BY_LASTNAME_FETCH_ORDERS,
queryString = "FROM CustomerData c LEFT JOIN FETCH c.orders WHERE c.lastname = :lastname")
})
@Cache(usage=READ_WRITE, region="CustomerCache")
public abstract class KundeData implements java.io.Serializable {
@Id(generate=AUTO, generator="customer_sequence_name")
@SequenceGenerator(name="customer_sequence_name",
sequenceName="customer_sequence")
protected long id = 0;

@Version
protected int version = 0;
...
}


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