-->
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.  [ 4 posts ] 
Author Message
 Post subject: Array saved only on update, not on insert
PostPosted: Mon Jul 02, 2007 10:58 am 
Newbie

Joined: Tue Jun 26, 2007 3:24 pm
Posts: 11
When I create a new object, then persist it, the array is not saved; however if I update it after it has been created, the array is saved. I have cascade set to "all", and it is performing the insert statements, but parent_id is being set to 0. The id attribute of MyObject defaults to undefined when a new instance is created and I have a generator set up for when it is stored in the database

Hibernate version:
3.0

Mapping documents:
This array is inside of another object.
Code:
<hibernate-mapping>
    <class name="MyObject" table="table1">
       
        <id name="id" type="int">
            <column name="id" not-null="true" unique-key="true"/> 
            <generator class="assigned"/>
        </id>

        <array name="variable" cascade="all" table="table2">
            <key foreign-key="true" column="parent_id" unique="false" not-null="true" />
            <list-index column="idx" />
            <element column="array_column" type="string" not-null="true" />
        </array>
    </class>
</hibernate-mapping>




Code that persists/updates object:
I use spring's HibernateTemplate:
Code:
MyObject object = new MyObject({"a", "b", "c"}); //array passed to constructor
getHibernateTemplate().saveOrUpdate(object);


Name and version of the database you are using:
MySQL

The generated SQL (show_sql=true):
This is what I get when I try to insert the new object containing the array:
Code:
Hibernate: insert into table1 (col1, col2, col3, col4) values (?, ?, ?, ?)
Hibernate: insert into table2 (parent_id, idx, array_column) values (?, ?, ?)
Hibernate: insert into table2 (parent_id, idx, array_column) values (?, ?, ?)
Hibernate: insert into table2 (parent_id, idx, array_column) values (?, ?, ?)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 3:41 pm 
Beginner
Beginner

Joined: Thu Feb 22, 2007 6:08 am
Posts: 35
Hi!

Try to see if the registry is persisted on the DataBase. If so, the problem is on the retrieve of the data. It seams the problem because i see 1 insert on the table1 and 3 ont the table 2.

--ms


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 10:10 am 
Newbie

Joined: Tue Jun 26, 2007 3:24 pm
Posts: 11
Thanks for your help, but I'm not really sure what your saying the problem is. I did a little more looking and it appears that the autonumber generator is not generating numbers. It always puts in 0. I figured out that "assigned" tells it not to assign a number.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 10:34 am 
Beginner
Beginner

Joined: Thu Feb 22, 2007 6:08 am
Posts: 35
well if that is the problem, use the natevi generator that detect the database and the better id type

Code:
<class name="Category" table="CATEGORY">
    <id name="id" column="CATEGORY_ID" type="long">
        <generator class="native"/>
    </id>
    ...
</class>



--ms

**dont forget to rate if it helped**


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