-->
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.  [ 1 post ] 
Author Message
 Post subject: Need to OneToAny association
PostPosted: Fri Jan 21, 2011 12:37 pm 
Newbie

Joined: Wed Mar 11, 2009 7:15 am
Posts: 13
Image
I need association OneToMany from Country to superclass Place. It could be bidirectional. But Place is MappedSuperclass.
I would need something like @OneToAny but this type of association doesn't exist.
Superclass Place is ok, I think.
Code:
@MappedSuperclass
public class Place {
   private String name;
   private Country country;
   
   @Column
   public String getName() {
      return name;
   }

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

   @ManyToOne
   @JoinColumn(name="country_id")
   public Country getCountry() {
      return country;
   }

   public void setCountry(Country country) {
      this.country = country;
   }
}

Country:
Code:
@Entity
public class Country {
   private long id;
   private String name;
   private List<Place> places;

   @Any(metaColumn = @Column(name = "place_type"), fetch = FetchType.EAGER)
   @AnyMetaDef(idType = "integer", metaType = "string", metaValues = {
         @MetaValue(value = "C", targetEntity = City.class),
         @MetaValue(value = "R", targetEntity = Region.class) })
   @Cascade({ org.hibernate.annotations.CascadeType.ALL })
//   @JoinColumn(name="unnecessary") // if this, in table country I have field "unnecessary"
//   @OneToMany(mappedBy="country")  // if this, NullPointerException...
   public List<Place> getPlaces() {
      return places;
   }

   public void setPlaces(List<Place> places) {
      this.places = places;
   }

   @Column
   public String getName() {
      return name;
   }

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

   @Column
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   public long getId() {
      return id;
   }
   public void setId(long id) {
      this.id = id;
   }
}

Please for help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.