-->
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: Hibernate 3.6 generate foreign key for share id
PostPosted: Thu Jan 27, 2011 11:24 am 
Newbie

Joined: Thu Jan 27, 2011 10:53 am
Posts: 12
Hi,
We used to generate our ddl using hibernateTool.
The following mapping:
Code:
@Entity
@Table(name="TB_SHARE")
public class BoShare implements Serializable {
    @Id
    @GeneratedValue(generator = "foreignGenerator")
    @GenericGenerator(name = "foreignGenerator",
                  strategy = "foreign",
                  parameters = { @Parameter
                      (name = "property",
                       value = "bomain")
                  }
    )
    private Long id;
    private String name;
    @Version
    private Integer version;
    @OneToOne(mappedBy="share",fetch=FetchType.LAZY)   
    protected BoMain bomain;

    //...(getters/setters/hashcode/equals)
}

@Entity
@Table(name="TB_MAIN")
public class BoMain implements Serializable {
    @Id
    private Long id;
    @Version
    private Integer version;
    private String name;
    @OneToOne(fetch=FetchType.LAZY)   
    @PrimaryKeyJoinColumn
    private BoShare share;
    //...(getters/setters/hashcode/equals)
}


With hibernate 3.3.2, that mapping produce the following ddl:
Code:
drop table TB_MAIN cascade constraints;
drop table TB_SHARE cascade constraints;
create table TB_MAIN (id number(19,0) not null, name varchar2(255 char), version number(10,0), primary key (id));
create table TB_SHARE (id number(19,0) not null, name varchar2(255 char), version number(10,0), primary key (id));

The binding sounds ok since the id of BoMain is properly used as id of BoShare.
The same mapping with hibernate 3.6.0 produced the ddl:
Code:
drop table TB_MAIN cascade constraints;
drop table TB_SHARE cascade constraints;
create table TB_MAIN (id number(19,0) not null, name varchar2(255 char), version number(10,0), primary key (id));
create table TB_SHARE (id number(19,0) not null, name varchar2(255 char), version number(10,0), primary key (id));
alter table TB_MAIN add constraint FKF0A5838ABA594AA3 foreign key (id) references TB_FSL_SHARE;

The generated foreign key on TB_MAIN prevent any insert in both table. Apparently during the secondPassCompile the @PrimaryKeyJoinColum is not taken into account.
Replacing it with @JoinColum(name="id") fix the problem.
Is it a problem with our mapping or change in the PrimaryKeyJoinColum are managed? In the second case, does it have any other impacts?
Best regards.


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.