-->
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.  [ 1 post ] 
Author Message
 Post subject: Default Value for List Index Mapping?
PostPosted: Fri Jan 26, 2007 11:31 pm 
Newbie

Joined: Mon Jan 15, 2007 11:03 pm
Posts: 2
Hi,

I apologize if this question has been asked many times before and is easy to find the answer to, but I did Google for a while for the answer and couldn't find anything very informative on this specific topic.

I have a List which is owned by the class User which is filled with objects of the class Blog.

Code:
class User {
     private List<Blog> blogs;
     ...


blogs is later actually implemented as a Vector.

Code:
blogs = new Vector<Blog>();


I have been trying to map this with Hibernate. I have created a table for User and Blog. However, the problem is storing the index. Everything else works fine, but when I try to run it, it says

SEVERE: Field 'position' doesn't have a default value


I put this field as an INT in MySQL in the blog table assuming that Hibernate would automatically place the correct index for each item in the list there. However, it seems it doesn't know what to put there.

My mapping files are as follows:

User.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="User" table="user">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="email" column="email" type="java.lang.String" />
<property name="encryptedPassword" column="password"
type="java.lang.String" />
<property name="registrationDate" column="registration"
type="java.util.Date" />
<property name="lastSignIn" column="last_signin"
type="java.util.Date" />
<property name="lastIp" column="last_ip"
type="java.lang.String" />
<list name="blogs" inverse="false" cascade="all">
<key column="user_id" />
<index column="position" />
<one-to-many class="Blog" />
</list>
</class>
</hibernate-mapping>

Blog.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="Blog" table="blog">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="title" column="title" type="java.lang.String" />
<property name="subtitle" column="subtitle"
type="java.lang.String" />
<property name="creationDate" column="creation"
type="java.util.Date" />
<many-to-one name="user" column="user_id" not-null="true" />
</class>
</hibernate-mapping>

Is there any special syntax I need to include to correct this? Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.