-->
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: java.util.Map @OneToMany doesn't retrieve all data
PostPosted: Mon Mar 03, 2008 2:01 pm 
Newbie

Joined: Mon Mar 03, 2008 1:32 pm
Posts: 2
Hibernate: 3.2.6
Annotations: 3.3.0
EntityManager: 3.3.1

Retrieving all Category doesn't retrieve all CategoryDescription.

After executing this query:
Code:
em.createQuery("SELECT c FROM Category c").getResultList()


Retrieving a CategoryDescription inside a TableModel using
Code:
CategoryDescription description = dataRow.getDescription().get(columnLanguage[columnIndex]);

(where columnLange is an array of Language objects).
I get a null result for row 0 and column 1.
The following rows return a correct value for column 1.
Inside NetBeans debugger I can see the correct value for row 0 but using the get() function doesn't not return the correct value.

If I chane the @OneToMany definition to @OneToMany(fetch=FetchType.EAGER) row 0 is returned correctly but I don't receive correct results (alwas null) for the last row. Very strange...

The following definitions:
Code:
@Entity
public class Category implements java.io.Serializable {
    @Id
    @GeneratedValue
    private Long id;

    @OneToMany
    @JoinColumn(name = "CATEGORY_ID")
    @MapKey(name="language")
    private Map<Language, CategoryDescription> description = new HashMap<Language, CategoryDescription>();
    ...

@Entity
public class Language implements java.io.Serializable {
    @Id
    @GeneratedValue
    private Long id;

    @Column(length=10)
    private String code;
    ...

@Entity
public class CategoryDescription implements java.io.Serializable {
    @Id
    @GeneratedValue
    private Long id;
   
    @ManyToOne(optional=false)
    private Language language;

    private String text;
    ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 4:21 am 
Newbie

Joined: Mon Mar 03, 2008 1:32 pm
Posts: 2
No one can help?

I tried to find out what is going wrong. I'm sure it is a hibernate error.

My database contains 10 categories with 2 language descriptions each. My test program exports all categories with all descriptions.
I if use LAZY fetching the first row (category 1, language 1) is not retrieved. Changing to EAGER fetching doesn't retrieve the last row correctly (category 10, language 1 is missing).

I turned on SQL statement logging and the correct statements are executed with correct results.


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.