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: @OneToAny or else
PostPosted: Tue Feb 23, 2010 5:32 am 
Newbie

Joined: Mon Apr 19, 2004 5:56 am
Posts: 9
Good morning,
i would like to map a bidirectional @Any association.

Can you tell me if there is a @OneToAny or else in order to manage the bidirection ?

Best Regards.


Top
 Profile  
 
 Post subject: Re: @OneToAny or else
PostPosted: Thu Feb 25, 2010 4:17 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Use @OneToMany
If you want to have the relation bidirectional, then you additionally must define the mappedBy property.


Top
 Profile  
 
 Post subject: Re: @OneToAny or else
PostPosted: Mon Oct 04, 2010 2:04 pm 
Newbie

Joined: Fri Jul 09, 2010 1:24 pm
Posts: 11
I have tried mappedBy in a @OneToOne, but that fails with the following message:

Quote:
Referenced property not a (One|Many)ToOne


Can this not be done? I am trying to use the @Any annotation to map a field that is an interface. Here's the full stack:


Code:
Caused by: org.hibernate.AnnotationException: Referenced property not a (One|Many)ToOne: com.xyz.domain.workflow.def.EntityInfo.businessEntity in mappedBy of com.xyz.domain.provider.Provider.entity
   at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:220)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1221)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:383)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)
   at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1459)
   at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1086)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:685)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
   at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
   at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
   ... 24 more


EDIT: I found a ticket in JIRA similar to what I am looking for, but I am not sure that means there isn't a way to achieve this so I am leaving my question open: http://opensource.atlassian.com/project ... e/HHH-4320


Top
 Profile  
 
 Post subject: Re: @OneToAny or else
PostPosted: Mon Dec 27, 2010 5:57 pm 
Newbie

Joined: Tue Oct 14, 2008 3:08 pm
Posts: 8
Location: Brasil
pb00067 wrote:
Use @OneToMany
If you want to have the relation bidirectional, then you additionally must define the mappedBy property.


I'm using @OneToMany with mapped by, but getting this error:

Exception in thread "main" org.hibernate.MappingException: Foreign key (FKC131381C3D434C46:journals [journalized_type,journalized_id])) must have same number of columns as the referenced primary key (issues [id])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:113)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:96)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1310)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1217)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1333)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)

My classes are:


@Entity
@Table(name="journals")
public class Journal {

@Id
private Integer id;

@Any(metaColumn = @Column(name = "journalized_type"))
@AnyMetaDef(idType = "integer",
metaType = "string",
metaValues = { @MetaValue(value = "Issue", targetEntity = Issue.class), //@MetaValue(value = "Board", targetEntity = Board.class) }
)
@JoinColumn(name="journalized_id")
private Journalized journalized;
...

@Entity
@Table(name="issues")
public class Issue implements Journalized {

@Id
private Integer id;

@OneToMany(mappedBy="journalized")
//@Where(clause="journalized_type = 'Issues'")
private List<Journal> journals;

...



Any ideas?

_________________
Bruno Medeiros


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.