-->
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.  [ 4 posts ] 
Author Message
 Post subject: Annotation, generic abstract class
PostPosted: Thu Dec 17, 2009 5:10 am 
Newbie

Joined: Thu Feb 19, 2009 7:15 am
Posts: 11
Hi @ all,

Hibernate-core: v.3.3.2
Hibernate-Annotations: v.3.4.0
Hibernate-Common-Annotations: v.3.1.0


i got an exception while implementing an abstract generic class:

Code:
Caused by: org.hibernate.AnnotationException: Property org.portfolio.data.ReportElement.content 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
   at org.hibernate.cfg.AnnotationBinder.addElementsOfAClass(AnnotationBinder.java:1032)
   at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:882)
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:667)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1333)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
   at org.portfolio.data.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:36)


My abstract class is:
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "ReportElement")
public abstract class ReportElement<T, E> implements Serializable,
      Comparable<ReportElement<T, E>> {

   private static final long serialVersionUID = 1L;

   protected T content;

   @Id
   @GeneratedValue
   @ManyToOne
   @JoinColumn(name = "element_fk", insertable = false, updatable = false)
   private long Id;

   protected E status;

   public abstract void addContent(T Content);

   public abstract int compareTo(final ReportElement<T, E> o);

   public abstract T getContent();

   public long getId() {
      return this.Id;
   }

   public abstract E getStatus();

   public abstract void setContent(final T content);

   public void setId(final long id) {
      this.Id = id;
   }

   public abstract void setStatus(final E status);

}


And the client:
Code:
@Entity
@Table(name = "ReportElementSingleContent")
public class ReportElementSingleContent extends ReportElement<String, Boolean> {

   private static final long serialVersionUID = 1L;

   @Override
   @Column(nullable = false)
   public void addContent(final String Content) {
      super.content = this.content;
   }

   public void addInformations(final String content, final Boolean status) {
      this.setContent(content);
      this.setStatus(status);
   }


   @Override
   public int compareTo(final ReportElement<String, Boolean> o) {
      return 0;
   }


   @Override
   public String getContent() {
      return super.content;
   }

   @Override
   @Column(nullable = false)
   public Boolean getStatus() {
      return super.status;
   }

   @Override
   public void setContent(final String content) {
      super.content = content;
   }

   @Override
   public void setStatus(final Boolean status) {
      super.status = status;

   }
}


Can someone please help me?

Regards


Top
 Profile  
 
 Post subject: Re: Annotation, generic abstract class
PostPosted: Thu Dec 17, 2009 2:51 pm 
Newbie

Joined: Thu Dec 17, 2009 2:46 pm
Posts: 5
Hi!

Since ReportElement is a superclass you should annotate it with a @MappedSuperclass. I hope it works for you


Top
 Profile  
 
 Post subject: Re: Annotation, generic abstract class
PostPosted: Thu Dec 17, 2009 3:36 pm 
Newbie

Joined: Thu Dec 17, 2009 2:46 pm
Posts: 5
Hi!

Since ReportElement is a superclass you should annotate it with a @MappedSuperclass. I hope it works for you


Top
 Profile  
 
 Post subject: Re: Annotation, generic abstract class
PostPosted: Wed Sep 15, 2010 7:46 am 
Newbie

Joined: Wed Sep 15, 2010 7:15 am
Posts: 2
I've tried for 2.5 days to create something similar, in my case a generic super class with an attribute "status" of Enum type.

To put it very simple: It seems impossible to achieve the expected result using Hibernate.

My inheritance is JOINED and I would like Hibernate to pick the correct enum type for the "status" attribute so I wouldn't have to replicate code/attributes and possibly table columns across the subclasses. I've tried many approaches including a creation of an innocuous superclass just to change @Entity for @MappedSuperclass and also writing a very specific UserType for this purpose, but always fell into the same problem: at one point or another Hibernate insists in picking a wrong enum class.

Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@SequenceGenerator(name = AbstractEntity.GENERATOR, sequenceName = "S_TRACEABLE_ENTITY")
public abstract class TraceableEntity<S extends Enum<S> & Status>  extends AbstractEntity {

    @Enumerated(EnumType.STRING)
    private S status;

    ...
}


Right now I'm writing very ugly code to workaround this limitation.

For the next project I'll try other ORM tools to check if any is capable of beautifully handle this case.


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