-->
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: query only (no updates) triggers delete and then insert
PostPosted: Sat Jan 19, 2008 10:40 pm 
Newbie

Joined: Sat Jan 19, 2008 10:29 pm
Posts: 1
Here is the scenario:
Suppose a Person is associated with a set of Events:

public class Person{
public Long id;
public int age;
public String firstName;
public String lastName;
public Set<Event> events = new HashSet<Event>();
}


public class Event{
private String title;
private Date date;
}

And then here is the mapping file for the Person (Event is a value type so it doesn't have mapping file)

<class name="Person" table="person">
<id name="id">
<generator class="native" />
</id>
<property name="age" />
<property name="firstName" />
<property name="lastName" />
<set name="events">
<key />
<composite-element class="Event">
<property name="title" />
<property name="date" />
</composite-element>
</set>
</class>

At last, here is the test function. As you can see, we modify nothing about the database, only queries:

Public Class Test{
private void loadEvent(){
Sessionsession=
HibernateUtil.getSessionFactory().getCurrentSession();
Transaction t = session.getTransaction();
t.begin();
Person p = (Person)session.get(Person.class, 1l);
p.getEvents().size(); //we only want to get the event size
t.commit();
}
}

When run this test, hibernate will reports the collection event of Person class is dirty and then:
1.delete all events from the table
2.reinsert them

Am I missing something? and any solutions for that problem? Thanks a lot!


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.