-->
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.  [ 7 posts ] 
Author Message
 Post subject: Generics with JPA
PostPosted: Mon Nov 15, 2010 2:51 pm 
Newbie

Joined: Tue Jun 09, 2009 1:43 pm
Posts: 10
Hello, I am having a problem using JPA with Generics. I have a class similar to the following:
Code:
@MappedSubclass
public abstract class Person<A extends AddressEntry> {
    @OneToMany(mappedBy = "person")
    @MapKey(name = "zip")
    public Map<ZipCode, A> getAddressMap() { return addressMap; }
    public void setAddressMap(Map<ZipCode, A> map) { addressMap = map; }
    private Map<ZipCode, A> addressMap;
}


I get the following exception:
org.hibernate.AnnotationException: Property Person.addressMap has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type

Note: I am using hibernate 3.5.2 and hibernate JPA v 2.0.0-1.0.0


Last edited by mjsabin01 on Fri Nov 19, 2010 10:15 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Generics with JPA
PostPosted: Wed Nov 17, 2010 11:30 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
What is your instance class?


Top
 Profile  
 
 Post subject: Re: Generics with JPA
PostPosted: Wed Nov 17, 2010 11:35 am 
Newbie

Joined: Tue Jun 09, 2009 1:43 pm
Posts: 10
The instance clases are similar to the following:

Code:
public class CommuterHomeAddress {
    ...
}

public class CommuterPerson extends Person<CommuterHomeAddress> {
   ...
}


Top
 Profile  
 
 Post subject: Re: Generics with JPA
PostPosted: Fri Nov 19, 2010 6:00 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Do you have setter there?


Top
 Profile  
 
 Post subject: Re: Generics with JPA
PostPosted: Fri Nov 19, 2010 9:59 am 
Newbie

Joined: Tue Jun 09, 2009 1:43 pm
Posts: 10
I had the setter originally in the base class. If i moved the getter and setter to the concrete class and remove the generics, it seems to work. But i would prefer to keep it in the base class, so i don't need to re-implement the getter / setter in every subclass.


Top
 Profile  
 
 Post subject: Re: Generics with JPA
PostPosted: Fri Nov 19, 2010 10:12 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
mjsabin01 wrote:
I had the setter originally in the base class. If i moved the getter and setter to the concrete class and remove the generics, it seems to work. But i would prefer to keep it in the base class, so i don't need to re-implement the getter / setter in every subclass.


I do not see setter in your base class.


Top
 Profile  
 
 Post subject: Re: Generics with JPA
PostPosted: Fri Nov 19, 2010 10:15 am 
Newbie

Joined: Tue Jun 09, 2009 1:43 pm
Posts: 10
updated the original post...


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