-->
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.  [ 6 posts ] 
Author Message
 Post subject: @Version annotation : Hibernate version:3.2.1.ga
PostPosted: Thu Apr 26, 2007 9:02 am 
Beginner
Beginner

Joined: Fri Apr 20, 2007 1:07 am
Posts: 23
Hi,

We have an address entity with the country entity embedded into it using @OneToOne unidirectional technique, CascadeType.REFRESH.
The issue is, on save or modify involving address, it expects the country object with the Version set along with the CountryId(The PK in Country which is the FK in Address table).

And it accepts any value even if it doesn't match with the original Version of the country object.

If version is not set, the save/modify fails with the error:

save transient object Country before Saving Address.

The code is given below.

Hibernate version:3.2.1.ga

Mapping documents:

Address entity:

@Entity
@Table(name="P_CRM_CLIENT_ADDRESS")
public class Address{
protected Long addressId;
protected String address;
protected Country countryObj;

//getters and setters for addressId and address

@OneToOne (cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
@JoinColumn(name = "COUNTRY_ID")
public Country getCountryObj() {
return countryObj;
}

public void setCountryObj(Country countryObj) {
this.countryObj = countryObj;
}
}

Country entity:

@Entity
@Table(name = "REF_COUNTRY")
public class Country
{
protected String countryId;
protected String countryDescription;
protected Long versionNo;

//getters and setters for countryId and countryDescription

@Version
@Column(name = "VER_NO")
public Long getVersionNo() {
return versionNo;
}

public void setVersionNo(Long versionNo) {
this.versionNo = versionNo;
}

}

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

Full stack trace of any exception that occurs:

Name and version of the database you are using: Oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Any help regarding this issue is appreciated.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 7:52 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
You're only cascading refreshes so an unsaved Country would cause this error. Did I miss the point? Try CascadeType.ALL...

-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 12:21 am 
Beginner
Beginner

Joined: Fri Apr 20, 2007 1:07 am
Posts: 23
No. I need CascadeType.REFRESH only. Because the country table is a master table that should not be altered by any object into which it is embedded.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 8:28 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
How are you getting the Country instance? You can't just drop in a new instance with the correct ID and version. You have to load it, optimally from cache. It's reference data, correct? Maybe even make it read only and immutable. If that's the case, I probably would not version it either.

-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 10:02 am 
Beginner
Beginner

Joined: Fri Apr 20, 2007 1:07 am
Posts: 23
I provide the page to save the address, with a drop down list of countries loaded from the DB for now. But the point is a cascade type of REFRESH should not need the version number right? I am already making it clear that the embedded object will not change. Or have i got that wrong?

And another point is it doesn't complain if the version number of the embedded country object sent along(during persisting the base object- address in this case), does not match with the version number of the originally loaded country object in the list.

It just needs a number set for the version field. That is all.

I can always send along any number. But it doesn't make any sense as to why such a behaviour is shown.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 10:11 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Post the code and let's go from there.

-Chris


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