-->
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: How to map java generics and wildcards
PostPosted: Tue Feb 27, 2007 3:37 pm 
Beginner
Beginner

Joined: Fri Jan 26, 2007 3:16 pm
Posts: 24
Hibernate version: 3.2.2-ga
Hibernate Annotations version: 3.2.1-ga

Hi, I'm trying to setup an inheritance hierarchy on a property using Java generics, but I am getting the following exception:

Quote:
org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined


So, either the syntax of what I'm trying to do is incorrect, or just not supported by Hibernate. Any help solving the simple example described below would be greatly appreciated.

The area I'm working in is the GIS domain, where we have entity objects that represent POINT, LINE, AREA, etc. geometric features. Each of these objects also has attributes attached to them, thus there is a POINT_ATTRIBUTE, LINE_ATTRIBUTE, AREA_ATTRIBUTE table. The DDL for the attribute tables is identical, thus the Entity objects PointAttribute, LineAttribute, AreaAttribute has all the same methods essentially.

So, I need to abstract out a generic interface. For example on the Point entity object I want to do this:

Code:
@Entity
@Table(name = "POINT")
public final class Point {

private Set<PointAttribute> pointAttributes;

   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "point")
   @Target(PointAttribute.class)
   public final Set<? extends Attribute> getAttributes() {
      return pointAttributes;
   }
}


I use the Target annotation to tell hibernate what the concrete type is there.

Then I have the class PointAttribute:

Code:
@Entity
@Table(name = "POINT_ATTRIBUTE")
public class PointAttribute implements Serializable, Attribute {
  // getters/setters
}


...and finally I have the Attribute interface:

Code:
public interface Attribute extends Serializable {
  // same getters/setters
}


The idea is that I can do this for each Point, Line, Area class, so the common return type on each is Attribute since the method signatures are the same for all *Attribute domain objects.

Unfotunately, if I try this, I get the exception noted above. What am I doing wrong?

Thanks in advance,
Davis


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 4:42 pm 
Beginner
Beginner

Joined: Fri Jan 26, 2007 3:16 pm
Posts: 24
problem self-solved; perhaps it will help someone else...

Code:
private Set<? extends Attribute> pointAttributes;

   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "point", targetEntity=PointAttribute.class)
   public final Set<Attribute> getAttributes() {
      return pointAttributes;
   }


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.