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!