-->
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: @SecondaryTable duplicate rows
PostPosted: Wed May 30, 2012 6:57 am 
Newbie

Joined: Wed May 30, 2012 6:35 am
Posts: 1
Hi,

I'd like to set up this:

@Entity
@Table(name = "A", uniqueConstraints = {})
@org.hibernate.annotations.Table(appliesTo = "B", indexes = {})
@SecondaryTable(name = "AA", pkJoinColumns = {@PrimaryKeyJoinColumn(columnDefinition = "A_ID", name = "A_ID")})
class A {

@Column(name = "A_1", nullable = false)
Integer a1;

@Column(name = "A_1", table = "AA", nullable = false)
private Integer aa1;

public void setVirtualRamInMb(final Integer n)
{
this.a1 = n;
this.aa1 = n;
}

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "A_B", joinColumns = {@JoinColumn(name = "A_ID")}, inverseJoinColumns = {@JoinColumn(name = "B_ID")})
List<B> bs;
}

@Entity
@Table(name = "B")
@SecondaryTable(name = "A_B", pkJoinColumns = {@PrimaryKeyJoinColumn(columnDefinition = "B_ID", name = "B_ID")})
@org.hibernate.annotations.Table(appliesTo = "B")
class B {

@Column(name = "b1", nullable = true)
private long b1;

@Column(name = "ab1", table = "A_B", nullable = true)
private long ab1;


public void setSize(final long n)
{
this.b1 = n;
this.ab1 = n;
}

@ManyToMany(mappedBy = "bs", fetch = FetchType.LAZY)
private List<A> as;
}

when creating a B object and adding it to a A object, in the table A_B I end up with two results instead of one. In one the relation is ok but the ab1 is 0 (default) in the other the relation with A is null but ab1 is ok.

Is this the expected behavior?

PS: I can provide a simple example (maven) with a main to show it up.

Thanks.

Regards.

ssedano.


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.