-->
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: Simple collection mapping problem with annotations
PostPosted: Tue May 22, 2007 10:12 am 
Newbie

Joined: Thu Oct 27, 2005 7:59 am
Posts: 5
I know this is very basic question, but i dont seem to find answer for it. i know how to do this with mapping files but i want to learn hibernate annotations.


I have two classes:
Code:
@Entity
public class Forum {

...

   @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
   private Integer id;

   @OneToMany(cascade = CascadeType.ALL, mappedBy="forum")
   @OrderBy("order")
   @Fetch(FetchMode.JOIN)
   private List<Area> areas;
...
}

@Entity
public class Area {
...
   @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
   private Integer id;

   @ManyToOne
   public Forum getForum() {
      return forum;
   }
...
}

they also have equals methods that make them equal by id

i have persited 3 forums, 1st with 2 areas, 2nd with one, and 3rd with 2.

i'll try getting these 3 Forums with every one correctly setted Areas with
Code:
      Criteria criteria = session.createCriteria(Forum.class)
      .setFetchMode("areas", FetchMode.JOIN)
      .addOrder(Order.asc("order"));
      List list = criteria.list();

but that list contains 5 Forums. 2x Forum 1, Forum 2 and 2x Forum 3.
there is created as many forums as there is areas. and every forum contains correct amount of areas. both copies of Forum 1 has 2 areas and so on.


Hibernate version: 3.2
Hibernate Annotations version: 3.3.0 GA

Name and version of the database you are using: MySql 5.0

The generated SQL (show_sql=true): this returns every area joined with correct forum row


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.