-->
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.  [ 2 posts ] 
Author Message
 Post subject: @OneToMany with @JoinTable and an id Generator for the table
PostPosted: Tue Aug 23, 2011 6:41 am 
Newbie

Joined: Wed Sep 03, 2008 9:56 am
Posts: 6
Hi Users,

A basic question but somehow I got messed up with:

I am mapping a Set (might be a list) of entities to an object using a mapping table.
Code:
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name="KW_TARGET_OPERATION_TEMPLATE_XREF", joinColumns={ 
    @JoinColumn(name="TARGET_OPERATION_ID") }, inverseJoinColumns={   
    @JoinColumn(name="TEMPLATE_ID", referencedColumnName="TARGETING_TEMPLATE_ID") })
private Set<TargetingTemplateVO> templates = new HashSet<TargetingTemplateVO>();


Now, the @JoinTable --> KW_TARGET_OPERATION_TEMPLATE_XREF has a surrogate column for setting a surrogate primary key (other two columns are primary key together).

What I'm trying to do is to make sure hibernate set this surrogate key using a sequence I have (in the database).

What's the best way to achieve this?

Thanks a lot,

David Zonsheine


Top
 Profile  
 
 Post subject: Re: @OneToMany with @JoinTable and an id Generator for the table
PostPosted: Tue Aug 23, 2011 11:49 am 
Newbie

Joined: Mon Dec 10, 2007 7:03 am
Posts: 14
TargetingTemplateVO should look like
Code:
@Entity @Table(name="TARGETING_TEMPLATE")
@SequenceGenerator(name = "TargetingTemplateSeq", sequenceName = "TARGETING_TEMPLATE_SEQ", allocationSize = 1)
public class TargetingTemplateVO  {
    @Id
    @Column(name = "TARGETING_TEMPLATE_ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TargetingTemplateSeq")
    private Long id;


The referencedColumnName="TARGETING_TEMPLATE_ID" is useless in parent object.


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