-->
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.  [ 3 posts ] 
Author Message
 Post subject: join over columns from both primary and secondary tables
PostPosted: Tue Jan 17, 2012 4:52 am 
Newbie

Joined: Thu Sep 02, 2010 5:54 am
Posts: 6
Hello,
I must map an existing model that's more or less like that :
    - A has a foreign key to B;
    - Each one of A and B has a part of a foreign key to C

The mapping I tried until now is like that :

Code:
@Entity
class A {
  @Id(name="A_ID")
  public Long key;

  @Column(name="A_CID1")
  public Long fkToC;

  @JoinColumn(name="A_BID", referencedColumnName="B_ID")
  public B b;
}

@Entity @Secondarytable(name="A")
class B {
  @Id(name="B_ID")
  public Long key;

  @Column(name="B_CID2")
  public Long fkToC;

  @JoinColumns({
    @JoinColumn(table="A", name="fkToC", updatable=false, insertable=false),
    @JoinColumn(table="B", name="fkToC", updatable=false, insertable=false)
  })
  public C c;
}

@Entity
class C {
  @Column(name=C_ID1)
  public Long id1;

  @Column(name=C_ID2)
  public Long id2;
}


It seems it won't work, as I get somme error :
Code:
Caused by: org.hibernate.AnnotationException: Mixing different tables in a property is not allowed: com.cs.services.bcmail.entity.MonitoringEventmonitoringReport
   at org.hibernate.cfg.Ejb3Column.checkPropertyConsistency(Ejb3Column.java:424)
   at org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:1982)
   at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1362)
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:755)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1161)
   at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1227)
   at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:855)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:426)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)
   at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
   at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419)
   ... 43 more


I'd like to
    - make sure is really what I understand, i.e. one cannot have a join over columns from different tables
    - find out how this can be mapped if it is not possible to do it like I tried.

Edit : added forgotten "updatable", "insertable".
Edit2 : added class C.


Top
 Profile  
 
 Post subject: Re: join over columns from both primary and secondary tables
PostPosted: Wed Jan 18, 2012 5:28 am 
Newbie

Joined: Thu Sep 02, 2010 5:54 am
Posts: 6
I'd be reallt grateful for some help here.

BTW, the hibernate versions I tested with are 3.3.? (whatever is in jboss eap 5.1) and 3.6.8.


Top
 Profile  
 
 Post subject: Re: join over columns from both primary and secondary tables
PostPosted: Wed Jan 18, 2012 8:20 am 
Newbie

Joined: Thu Sep 02, 2010 5:54 am
Posts: 6
Nobody ?


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