Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JBoss User Help »

[jboss-user] [EJB 3.0] - @SecondaryTable. How to use it?

scott.stark@jboss.org

2007-06-15


How can I use @SecondaryTable?

I have a Contact entity which defines a person's email, phone etc. There may be several of these pointing to a single Person entity.

Because a person may belong to several organizations, and have several contactable personas.

So. I want to create a ContactPerson entity from two tables.

It seems that I have to have the primary table as the Person table because there are many Contacts, and they have a foreign key which points to the Person's primary key, and it only works this way round, the seconary pointing to the primary. You can't have a FK on the primary pointing to the secondary!!!

But obviously, the @Id field cannot be the id field of that primary table, the Person table. Because it will be repeated several times, once for each Contact that's linked to it.

so I have


| @javax.persistence.Table(name="Person")
| @SecondaryTable(name="ContactDetails",
|    pkJoinColumns=@(protected)"),
|    uniqueConstraints = @UniqueConstraint(columnNames={"person_id", "player_id"})
| )
| public class ContactPerson extends CompositeEntity implements Serializable
| {
|  private Long id;
|  @Column(table="ContactDetails", name="id")
|  @Id
|  public Long getId() {
|    return id;
|  }
|  public void setId(Long id) {
|    this.id = id;
|  }
|   ...
|

And I think it's that ID that's causing the problem.

With this, I get


| org.hibernate.MappingException: Unable to find logical column name from physical name id in table person
|  org.hibernate.cfg.Mappings.getLogicalColumnName (Mappings.java:514)
|  org.hibernate.cfg.Ejb3JoinColumn.linkValueUsingDefaultColumnNaming (Ejb3JoinColumn.java:270)
|  org.hibernate.cfg.annotations.TableBinder.bindFk (TableBinder.java:214)
|  org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass (CollectionBinder.java:1253)
|  org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass (CollectionBinder.java:1101)
|  org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass (CollectionBinder.java:567)
|  org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:508)
|  org.hibernate.cfg.CollectionSecondPass.doSecondPass (CollectionSecondPass.java:43)
|  org.hibernate.cfg.Configuration.secondPassCompile (Configuration.java:1130)
|  org.hibernate.cfg.AnnotationConfiguration.secondPassCompile (AnnotationConfiguration.java:296)
|  org.hibernate.cfg.Configuration.buildMappings (Configuration.java:1115)
|  org.hibernate.ejb.Ejb3Configuration.buildMappings (Ejb3Configuration.java:1233)
|

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4054833#4054833

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4054833
_______________________________________________
jboss-user mailing list
jboss-user@(protected)
https://lists.jboss.org/mailman/listinfo/jboss-user
©2008 junlu.com - Jax Systems, LLC, U.S.A.