-->
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.  [ 7 posts ] 
Author Message
 Post subject: Self Referencing Relations...
PostPosted: Mon Feb 13, 2006 11:14 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
Hibernate: 3.1.1
Annotations: 3.1 beta8
OS: Windows XP
Database: MySQL 5.x

Table Message
messageId
parentMessageId

public class Message
{
Message getParentMessage(){...}
}

...

select {m.*} from Message

gives a "More than one Row with the same identifier"...removing getParentMessage() from Message fixed the problem.

Does Hibernate support "self-referencing" like above?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 11:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes why should it not.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 1:35 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
Yeah, why should it not work? It just does not work :)

Here is the query trace:

select * from Message m

select * from Message message0_ left outer join Message message1_ on message0_.messageOid=message1_.rootMessageOid where message0_.rootMessageOid=?

org.hibernate.HibernateException: More than one row with the given identifier was found: Message@ff665a, for class: Message
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:135)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:85)
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1522)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:365)
at org.hibernate.type.EntityType.resolve(EntityType.java:306)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:117)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1672)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:147)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 1:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
are you sure that is the query you run ? "select * from Message m" ? and do you do it through createSQLQuery().list() ?

anyways somehow your query or simply the database contains the same id for more than one row....have you chekked you data?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 2:12 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
max wrote:
are you sure that is the query you run ? "select * from Message m" ? and do you do it through createSQLQuery().list() ?

anyways somehow your query or simply the database contains the same id for more than one row....have you chekked you data?


Well, here is the exact query:

2006-02-13 22:00:21,375 DEBUG [ROOT] (HibernateFuncs.java:75) - SQLQueryImpl(select {m.*} from Message m where category=:p1 order by dateTime desc)

It is through createSQLQuery().list()...

messageOid is the PK for Message, so yeah, I am still scratching my head. Is it possible for Hibernate to log the offending object and its id?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 2:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes: More than one row with the given identifier was found: Message@ff665a, for class: Message

it does not include the id by default, but if you added that in the to-string then it would work.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 2:28 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
I found the problem. Here is the correct annotation:

@JoinColumn(name="rootMessageOid", referencedColumnName="messageOid", insertable=false, updatable=false)

Previously, I had the following ERRONEOUS annotation:

@JoinColumn(name="messageOid", referencedColumnName="rootMessageOid", insertable=false, updatable=false)


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