-->
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: Occasionally duplicated entries on using ManyToMany
PostPosted: Thu Jun 26, 2008 7:58 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 8:16 am
Posts: 23
Duplicated entries on using ManyToMany

Hi,

I'm working with a legacy database, that's why the database schema isn't that
fine. I'm using following classes:

Code:
@Entity
@Table(name = "TS_STATI")
class Status {

    @Id
    @Column(name = "STATUS_ID")
    private Long id;

    @ManyToMany
    @JoinTable(name = "TEXT2STATI2NAME",
            joinColumns = {
                @JoinColumn(name = "MAP_ID")
                },
            inverseJoinColumns = {
                @JoinColumn(name = "TEXT_ID", referencedColumnName = "TEXT_ID")
                })
    private List<TextResource> nameLocalized;

}

@Entity
@Table(name = "TEXT_RESSOURCE")
class TextResource {

    @Id
    @Column(name = "ROWID")
    private String id;

    @Column(name = "TEXT_ID")
    private Long textId;

    @Column(name = "SPRACHE")
    @Type(type = "LocaleType")
    private Locale locale;
   
    @Column(name = "TEXT")
    private String text;

}


As can imagine, the TextResource contains translations.

When i quering
Code:
from Status
the status object - in one of ten cases -
the TextResource list contains duplicate entries (e.g. three times the french
translation) and not one for each language.

The generated sql works fine.
Code:
SELECT namelocali0_.map_id AS map1_1_, namelocali0_.text_id AS text2_1_,
       textresour1_.ROWID AS rowid1_132_0_,
       textresour1_.sprache AS sprache132_0_, textresour1_.text AS text132_0_,
       textresour1_.text_id AS text4_132_0_
  FROM text2stati2name namelocali0_, text_ressource textresour1_
WHERE namelocali0_.text_id = textresour1_.text_id(+)
       AND namelocali0_.map_id = ?


Is it a hibernate bug or did I configure it in a wrong way. Maybe it has to
do with the ROWID or... Of course it is also not a pure m:n relation. It is
something like 1:1:n.

Hibernate Version: 3.2.6ga, Database Oracle: 9.

I hope you can help me.

Thank you in advance.

Best regards, Michi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 9:29 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
You could use a Set instead of a List, which would eliminate duplicate entries?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 9:37 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 8:16 am
Posts: 23
thank you for you quick replay. that would be ok for me, but the real problem is, that one of the list get duplicated and the rest got lost.

one example:
StatusA has following translations: DE:Status and EN:State. When loading it with hibernate the list contains EN:State twice and DE:Status get lost.

So, the list doesnt help me a lot.

Best regards, Michi


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.