-->
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.  [ 9 posts ] 
Author Message
 Post subject: More than one row with the given identifier was found
PostPosted: Sun Jun 13, 2004 11:19 am 
Newbie

Joined: Wed Jan 07, 2004 12:02 pm
Posts: 15
Location: Herne, Germany
Hello forum,

I have a problem with an inheritance mapping. I'm using hibernate version 2.1.4, mysql 4.1 alpha and mysql-connector 3.1.1 alpha.

I prepared a simple mapping file that produces a HibernateException with the message below when I try to load an instance of class test.hibernate.inherit.Child from the database. The exception is thrown whenever there is more than one row in the child table.

Code:
"More than one row with the given identifier was found: 4, for class: test.hibernate.inherit.Child

This is the mapping file:

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="test.hibernate.inherit.Parent"
        table="test_hibernate_inherit_parent"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="name"
        />

        <joined-subclass
            name="test.hibernate.inherit.Child"
            table="test_hibernate_inherit_child"
            dynamic-update="false"
            dynamic-insert="false"
        >
        <key
            column="id"
        />

        </joined-subclass>

    </class>

</hibernate-mapping>


Thanks for any help,

ruuit


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 13, 2004 1:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
The exception is thrown whenever there is more than one row in the child table.


The id property is intended to be the primary key, or at least a unique key, of the database table.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 13, 2004 3:21 pm 
Newbie

Joined: Wed Jan 07, 2004 12:02 pm
Posts: 15
Location: Herne, Germany
Quote:
The id property is intended to be the primary key, or at least a unique key, of the database table.


Yes, but I think in the mapping id is not defined as a usual property but as a primary key column for the table. The native generator class should provide unique primary key and the contents of the id column in the table are unique, indeed. I hope the mapping is defined correctly?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 12:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Set you DB column as a real PK, it won't ahppen again

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 1:40 pm 
Newbie

Joined: Wed Jan 07, 2004 12:02 pm
Posts: 15
Location: Herne, Germany
emmanuel wrote:
Set you DB column as a real PK, it won't ahppen again


Thanks for your reply Emmanuel.

Could you please be a little more specific? What do you mean by "real PK"? Is there something missing in the mapping file?

I use schema export for database creation and these are the create statements:
Code:
create table de_ruu_test_hibernate_inherit_child (
   id BIGINT not null,
   primary key (id)
) type=InnoDB;
create table de_ruu_test_hibernate_inherit_parent (
   id BIGINT NOT NULL AUTO_INCREMENT,
   name VARCHAR(255),
   primary key (id)
) type=InnoDB;

Is there anything wrong with that? BTW: mysql and other tools report existing primary keys for the tables.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 6:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, I don't uderstand
Do you have more than one row with ID=4, in de_ruu_test_hibernate_inherit_child ?
There should not

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 11:33 pm 
Newbie

Joined: Wed Jan 07, 2004 12:02 pm
Posts: 15
Location: Herne, Germany
emmanuel wrote:
Hum, I don't uderstand
Do you have more than one row with ID=4, in de_ruu_test_hibernate_inherit_child ?
There should not


No, I'm sure there is only one row in the child table, but of course there is one row with the same id in the parent table. I think this is how inheritance is meant to work, isn't it?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 3:11 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ruuit wrote:
emmanuel wrote:
there is one row with the same id in the parent table. I think this is how inheritance is meant to work, isn't it?

Correct if you use joined-table.
But if you have Parent <- ChildType1 and Parent <- ChildType2
An id has to be on Child1 or Child2 not both

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 4:21 am 
Newbie

Joined: Wed Jan 07, 2004 12:02 pm
Posts: 15
Location: Herne, Germany
Emmanuel,

thanks for your help. During weekend I managed to solve the problem. I traced mysql, found some strange output, did a little google investigation and found a hint that made me downgrade the mysql db to a stable (not alpha development) version. From there on this and other errors disappeared.

Thanks again!


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