Hi,
i have got a problem with setting the index of a List in may database-entries.
I have got an User-Object (mapping):
Code:
<?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 schema="..." package="...">
<class name="User" table="user" schema="..." optimistic-lock="none">
<id name="id" type="integer" unsaved-value="null" column="id">
<generator class="native"/>
</id>
<property name="userName" type="string" column="user_name"/>
...
<list name="characters" lazy="false" cascade="none">
<key foreign-key="User_id" update="false" column="user_id" />
<list-index base="0" column="characters_idx"/>
<one-to-many entity-name="com.g.dto.Character"/>
</list>
</class>
</hibernate-mapping>
A Character-Object (mapping):
Code:
<?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 schema="..." package="...">
<class name="Character" table="character" schema="..." optimistic-lock="none">
<id name="id" type="integer" unsaved-value="null" column="id">
<generator class="native"/>
</id>
...
<many-to-one name="user" entity-name="com.g.dto.User" cascade="none" foreign-key="User_id" not-null="true" column="user_id"/>
</class>
</hibernate-mapping>
I add a new character to the Userlist and stores the character with this snippet:
Code:
public static void addCharacter(Character character){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
// gets userobject from Session
// adds character to User and saves character
User user = JSFUtil.getManagedUserObject();
character.setUser(user);
user.getCharacters().add(character);
session.beginTransaction();
session.save(character);
session.getTransaction().commit();
}
Everything works fine, but the index of my characterList will be not set. If the character stored in the DataBase characters_idx is NULL. How could I set this index? Or should User make that automaticly? Couldnt I add a Character to the Database with adding that character to Users-Characterlist and session.save(User) instead of save the character into the DB?
I hope anyone can help me
Thnx
Alex