-->
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: Need help with @OneToOne
PostPosted: Tue Sep 13, 2005 7:26 pm 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Hi All,

We've been using hibernate annotations 3.1 beta 3 with hibernate 3.1 beta release. We've a class DataCenter which has one to one relationship with class Workgroup.

Here's how we've defined the annotations in DataCenter class (only relevant portion of DataCenter class):



Code:
public class DataCenter extends BaseAdminEntity {

private WorkGroup workgroup;

   @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="WORKGROUP_ID", referencedColumnName="id")   
    @NotNull
   public WorkGroup getWorkgroup() {
      return workgroup;
   }


Here's how the schema is generated:

Code:
create table DATACENTER (
    id number(19,0) not null,
    CREATED_DATE timestamp,
    CREATED_BY_ID number(19,0),
    CREATED_BY_NAME varchar2(64),
    MODIFIED_DATE timestamp,
    MODIFIED_BY_ID number(19,0),
    MODIFIED_BY_NAME varchar2(64),
    NAME varchar2(64) not null,
    IS_ACTIVE number(1,0) not null,
    DESCRIPTION varchar2(256) not null,
    WORKGROUP_ID number(19,0),
    primary key (id),
    unique (WORKGROUP_ID)
);



As you can see in the schema, one-to-one relationship with Workgroup has unique constraint. Is there a way i can remove this unique constraint for this column WORKGROUP_ID using annotations? The reason is that in our c ase each DataCenter will have one workgroup but it need not be unique.


Could someone please let me know how to remove the unique constraint in this case?


Thanks for any input in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 7:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
So it's a @ManyToOne

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 11:15 pm 
Newbie

Joined: Tue Sep 13, 2005 10:57 pm
Posts: 10
@Entity
Class DataCenter{
...
@Id(generate=...)
public int getId(){...}

@OneToOne(cascade = { CascadeType.ALL })
@PrimaryKeyJoinColumn
private WorkGroup workgroup;

public WorkGroup getWorkGroup(){
}
}

@Entity Class Workgroup{
@Id(generate=...)
public int getId(){...}

}
Maybe this help.
most default is ok?

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 5:10 pm 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Thanks emmanuel and xiangya. I think i'll go with @ManyToOne.


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.