-->
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: Value of Index column not automatically incrementing
PostPosted: Wed Mar 21, 2012 3:09 pm 
Newbie

Joined: Wed Mar 21, 2012 2:56 pm
Posts: 6
Hi,
I'm new here but have started working on a project that will likely use Hibernate as its storage interface, and hopefully Search at a later date too.

To get familiar with Hibernate I'm going through this tutorial:
http://viralpatel.net/blogs/2011/12/hibernate-one-to-many-xml-mapping-tutorial.html

But Step 8 of the tutorial, the point at which a "list-index" column is added to the "employee" table, does not seem to work.
<list name="employees" table="employee" inverse="false" cascade="all">
<key column="department_id" />
<list-index column="idx" />
<one-to-many class="net.viralpatel.hibernate.Employee" />
</list>

The value of the "idx" column is not automatically incrementing...

This is what I get:

mysql> select * from employee;
+-------------+-----------+----------+------------+------------+---------------+-----+
| employee_id | firstname | lastname | birth_date | cell_phone | department_id | idx |
+-------------+-----------+----------+------------+------------+---------------+-----+
| 1 | Nina | Mayers | 1970-01-01 | 1212 | 115 | 0 |
| 2 | Tony | Almeida | 1970-01-01 | 4343 | 115 | 0 |
+-------------+-----------+----------+------------+------------+---------------+-----+

This is what the tutorial claims I should get:
mysql> select * from employee;
+-------------+-----------+----------+------------+------------+---------------+-----+
| employee_id | firstname | lastname | birth_date | cell_phone | department_id | idx |
+-------------+-----------+----------+------------+------------+---------------+-----+
| 1 | Nina | Mayers | 1970-01-01 | 1212 | 115 | 0 |
| 2 | Tony | Almeida | 1970-01-01 | 4343 | 115 | 1 |
+-------------+-----------+----------+------------+------------+---------------+-----+

All code and configuration has been taken directly from the linked tutorial, so I won't add more listings unless requested.

Thanks in advance for any help.

Alex


Top
 Profile  
 
 Post subject: Re: Value of Index column not automatically incrementing
PostPosted: Thu Mar 22, 2012 3:11 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hm,

to me it looks, that this tutorial is simply wrong:
inverse="false" not only means that Department is relationship owner,
it also means that nothing of the relation should be stored in table employee.
Usually then a secondary table is created in the schema holding 3 columns: the primary key of Department , the primary key of employee, and the idx column.


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.