-->
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.  [ 3 posts ] 
Author Message
 Post subject: problem with @OneToMany connection between 2 tables
PostPosted: Mon Jan 07, 2008 4:32 am 
Beginner
Beginner

Joined: Mon Jan 07, 2008 4:13 am
Posts: 22
HI!

i have 2 tables - House and HouseContact:

DB: postgreSQL

table house: columns: id(bigint), name (varchar), address(varchar)

table house_contact: columns: id(bigint), name (varchar), fk_house_id (bigint) - foreign key to House table

Code:
@Entity @Table(name="house")
public class House extends BaseObject {

   private Long id;

   private String name = null;

   private String address = null;

   public House() {}

   @OneToMany (fetch = FetchType.LAZY, cascade = CascadeType.ALL)
   @JoinColumn(name = "fk_house_id")
   private List<HouseContact> houseContacts;

   public void addHouseContact(HouseContact houseContact) {
       if (this.houseContacts == null) {
           houseContacts = new ArrayList<HouseContact>();
       }
       this.houseContacts.add(houseContact);
       houseContact.setHouse(this);
   }

   public List<HouseContact> getHouseContacts() {
       return houseContacts;
   }

   public void setHouseContacts(List<HouseContact> houseContacts) {
       this.houseContacts = houseContacts;
   }

   ......
}

@Entity @Table(name="house_contact")
public class HouseContact extends BaseObject {

    private Long id;

    private String name = null;

    public HouseContact() {}

    @ManyToOne (fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "fk_house_id", nullable = false)
    private House house;

    public House getHouse() {
        return house;
    }

    public void setHouse(House house) {
        this.house= house;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_house_contact")
    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

.....
}


a I have this error message:

Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.List, for columns: [org.hibernate.mapping.Column(houseContacts)]

please, where is the problem ?

thanks!

Ivan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 6:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Check this out: http://opensource.atlassian.com/project ... se/ANN-315

It seems you are not consistent with your annotations. Either put all annotations on the properties or on the getters.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 8:10 am 
Beginner
Beginner

Joined: Mon Jan 07, 2008 4:13 am
Posts: 22
Thanks! everything is OK. Thanks! Ivan


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