-->
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: Does hibernate support persisting clases contaning generics?
PostPosted: Tue Mar 04, 2008 10:30 am 
Newbie

Joined: Tue Mar 04, 2008 10:00 am
Posts: 2
Location: italy
Hi , i'm new on this forum , i really spent a lot of time searching the web
why i can't define a class which is defined in function of a generic type.
To make the concept clear i have the class Broker defined as follows

@Entity
@DiscriminatorColumn(name="Type")
public abstract class Broker<M extends AbstractEntity, I extends Item>
{
@Id@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@ManyToOne
private M master;
@Transient
protected I detail;
private Integer detail_id;
public Broker()
{
}
public Broker(M contenitore, I contenuto)
{
this.master = contenitore;
setDetail(contenuto);
}
public Integer getId()
{
return id;
}
public void setId(Integer idDetails)
{
this.id = idDetails;
}
public M getMaster()
{
return master;
}
public void setMaster(M beta)
{
this.master = beta;
}
@SuppressWarnings("unchecked")
@Transient
public I getDetail() {
if (detail == null)
{
EntityManager em = JPAContext.entityManager();
detail = (I)em.find(getDetailClass(),this.getDetailId());
}
return detail;
}
@Transient
public synchronized void setDetail(I detail) {
this.detail = detail;
this.detail_id = detail.getId();
}
protected Integer getDetailId()
{
return detail_id;
}
protected abstract Class<?> getDetailClass()
;
}

javax.persistence.PersistenceException: org.hibernate.AnnotationException:

Property it.cspnet.jpa.Broker.master 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


and here is the stack trace in case it could be useful

at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:258)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at it.cspnet.jpa.TestScritturaBeta.inizializzaEntityManager(TestScritturaBeta.java:212)
at it.cspnet.jpa.TestScritturaBeta.setUp(TestScritturaBeta.java:41)
at junit.framework.TestCase.runBare(TestCase.java:132)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.AnnotationException: Property it.cspnet.jpa.Broker.master 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:993)
at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:833)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:645)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
... 19 more

What's the matter with that ?
Should i remove generics in the definition of the signature of the class?
How are generics managed by the persistence framework ?
Please help , i need to solve the problem or at least to have some advice
on how to fix it if it is possible and if it is not possible i would like to know so i can give up using it [/b]

_________________
Marijuana causes amnesia and other things I don't remember.


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.