-->
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: Problem with @AttributeOverride
PostPosted: Tue Sep 09, 2008 3:10 pm 
Newbie

Joined: Tue Sep 09, 2008 2:51 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.4.GA
Hibernate Annotation version: 3.4.0.GA

Hi, I am trying to use Embedded Objects/Components in annotation. In the code snippet below, I am trying to save only the name of countries that I have lived in. (Not the other properties of country, like flagColor).


public class Address implements Serializable {
String city;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="name", column = @Column(name="COUNTRY_NAME_1"))
})
Country country_lived_1;

@Embedded
@AttributeOverrides({
@AttributeOverride(name="name", column = @Column(name="COUNTRY_NAME_2"))
})
Country country_lived_2;
}

@Embeddable
public class Country implements Serializable {
@Column(name="countryName") private String name;
private String flagColor;

public String getName() { return name; }
public void setName(String name) { this.name = name; }

public String getFlagColor() { return flagColor; }
public void setFlagColor(String flagColor) { this.flagColor = flagColor; }
}

Error I got is :
org.hibernate.MappingException: Repeated column in mapping for entity: Address column: flagColor (should be mapped with insert="false" update="false")

It seems that all properties of country has to be defined in @AttributeOverrides, even though flagColor is not needed here.

Is there any way that only the name of the country can be retrieved from Country?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 7:17 pm 
Newbie

Joined: Mon Sep 01, 2008 6:57 pm
Posts: 2
Country is mapped to both a name and a flagColor; when you override the name property, I suspect that flagColor's mapping is unaffected, so it's looking for the mapped column in your Address's table (which won't exist). If you were mapping Country normally (without overrides), you'd mark it as @Transient, so I believe you need to do the same here, using @TransientOverride(name="flagColor", transient = true) on your Country objects within Address.

I haven't actually tried this, so I can't be sure it'll do the trick, but it seems logical to a fellow newbie...


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