-->
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: Strange composite-element behavior
PostPosted: Thu Jan 06, 2005 12:42 pm 
Regular
Regular

Joined: Tue Jul 13, 2004 2:27 am
Posts: 73
Location: Singapore
Hibernate version:2.1.6

Mapping documents:
<class name="net.canal.admin.persistence.Program" table="PROGRAMS">
<id name="id" type="long" column="PROGRAM_ID" unsaved-value="0">
<generator class="identity"/>
</id>

<!-- Program properties -->

<!-- Program News related properties -->
<set name="news" lazy="true" table="PROGRAM_NEWS" order-by="PUBLISH_TIME asc">
<key column="PROGRAM_ID"/>
<composite-element class="net.canal.admin.persistence.News">
<property name="headline" column="HEADLINE" />
<property name="author" column="AUTHOR" />
<property name="content" column="CONTENT" />
<property name="createTime" column="CREATE_TIME" />
<property name="publishTime" column="PUBLISH_TIME" />
</composite-element>
</set>

<!-- Program Milestone properties -->
<set name="milestones" lazy="true" table="PROGRAM_MILESTONE" order-by="MILESTONE_TIME asc">
<key column="PROGRAM_ID"/>
<composite-element class="net.canal.admin.persistence.Milestone">
<property name="name" column="NAME" />
<property name="description" column="DESCR" />
<property name="milestoneTime" column="MILESTONE_TIME" />
</composite-element>
</set>

</class>



Name and version of the database you are using:mySQL

The generated SQL table (show_sql=true):
create table PROGRAMS (
PROGRAM_ID bigint not null auto_increment,
NAME varchar(255) not null,
DESCR varchar(255),
ROOTFOLDER varchar(255),
TOTALFILES bigint,
TOTALACCESS bigint,
ORG_ID bigint not null,
primary key (PROGRAM_ID)
);
create table PROGRAM_NEWS (
PROGRAM_ID bigint not null,
HEADLINE varchar(255),
AUTHOR varchar(255),
CONTENT varchar(255),
CREATE_TIME datetime,
PUBLISH_TIME datetime
);



Hi,
I am having a very strange result. I defined a Program entity which has one composite-element for News and one for Milestone.

I have no problem operating on Milestones, however, when I add one news, the existing news are copied and stored again. So if currently I have a program P1 which has 3 piece of news, after adding 1, I will get 3+1+3 = 7. I do not understand why or how to debug this.

The code that handles save/get/update news and milestones are very much the same. the definition of class News and Milestone are also very similar.

Here is how I add news to a program (I am using Spring framework):
......
News n = new News();
BeanUtils.copyProperties (n, ...);
Program p = manager.getProgram (pid):
p.addNews (n);
manager.saveProgram (p);
......

public class Program ... {
......
private Set news = new HashSet();
private Set milestones = new HashSet();
......

public Set getNews () {
return this.news;
}

public void setNews (Set news) {
this.news = news;
}

public void addNews (News news) {
this.news.add(news);
}
.....
}

The manager class is very simple (in Spring framework):

getHibernateTemplate().update(p);

The strange thing is that everything is fine for Milestone. I can not figure out the difference.

thanks for your reading !
li xin


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 6:57 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
I am having a case like this, when one property of the composite-element has a null value.
Hibernate seems to delete and restore the composites each time and issues a query like

delete from xy where xy.propertyA = foo and xy.propertyB = bar
when propertyA is null ther query does not find any entries because the query should be:
delete from xy where xy.propertyA is null and xy.propertyB = bar

The reference mentions this.

Regards

Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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.