-->
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: Bidirectional one-to-one with join table - Generated SQL
PostPosted: Tue Nov 27, 2007 11:03 am 
Newbie

Joined: Sun Nov 25, 2007 3:30 pm
Posts: 3
Hibernate version:
Hibernate Core 3.2.5.GA
Hibernate Annotations 3.3.0.GA
Hibernate Entity Manager 3.3.1.GA

Name and version of the database you are using:
Microsoft SQL Server 2000/2005

We are trying to apply bidirectional one-to-one mapping with join table betwen two classes, but have problems with the generated SQL.
Consider simple example:

Code:
@Entity
public class Person {
  @Id
  private long id;

  @OneToOne(optional = false)
  @JoinTable(
    name = "Person_Address",
    joinColumns = @JoinColumn(name = "person_id"),
    inverseJoinColumn = @JoinColumn(name = "address_id")
  )
  private Address address;
}

@Entity
public class Address {
  @Id
  private long id;

  @OneToOne(mappedBy = "address")
  private Person person;
}


Generated (partial) SQL for the join table looks like following:
Code:
create table Person_Address (
  person_id numeric(19, 0) not null,
  address_id numeric(19, 0) not null,
  primary key (address_id),
  unique(address_id)
)


It looks a little strange to have both primary key and unique constraint defined on the same colum, right? We think that correct would be to have primary key defined on one column and unique constraint defined on second column.

Our question is: What is the correct way of mapping to achieve desired behavior - primary key on one column and unique constraint on second?


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.