-->
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: Repeated rows in manytoone relationship
PostPosted: Mon May 03, 2010 3:28 am 
Newbie

Joined: Sun Apr 04, 2010 2:21 am
Posts: 2
I have a problem I got a repeated rows in the parent entity as much as I insert a child in the database (e.g. if I insert 3 child to the same parent i got the parent repeated 3 times in the list returns from database) I use InheritanceType = TABLE_PER_CLASS.

the Enterprise entity
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Enterprise {

private Set<Contact> contact;
private Integer id;

   
   @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "enterprise",targetEntity=Contact.class)
   public Set<Contact> getContact() {
      return contact;
   }

   @Id
   @GeneratedValue(generator="idGen")
   @GenericGenerator(name="idGen",strategy="org.hibernate.id.IncrementGenerator")
   @Column(name = "ID", unique = true, nullable = false)
   public Integer getId() {
      return id;
   }

   public void setContact(Set<Contact> contact) {
      this.contact = contact;
   }

   public void setId(Integer id) {
      this.id = id;
   }

}


And the contact entity

Code:
Entity
@Table(name = "CONTACT")
public class Contact implements Serializable {

private Enterprise enterprise;
private Integer id;

@Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "ID", unique = true, nullable = false)
   public Integer getId() {
      return id;
   }
@ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "ENTERPRISE_ID")
   public Enterprise getEnterprise() {
      return enterprise;
   }

public void setEnterprise(Enterprise enterprise) {
      this.enterprise = enterprise;
   }
}


And the Vendor entity

Code:

@Entity
@Table(name = "VENDOR")
public class Vendor extends Enterprise implements java.io.Serializable {

----------------
}






I use Hibernate and Spring With JSF.

Code:

public List<T> findAll(T type) {
      // TODO Auto-generated method stub
      return getHibernateTemplate().loadAll((Class<T>) type);
   }


T is the Vendor entity.

the returned list contain a repeated parents as many as its child


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.