-->
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: Hibernate issues delete commands
PostPosted: Thu Jan 13, 2011 4:41 pm 
Newbie

Joined: Thu Jan 13, 2011 3:55 pm
Posts: 4
Hello everyone, this is my first post on this forum. I'm actually facing a really strange behavior with my application, and I've lost the last two days in unsuccessful tries to come out from it. Here's a brief description of the model and algorithm:
I've got several network hosts (routers), I query them via SNMP with a library which I wrote, and then I have to the store the query results into a database.
Both targets to be queried and query results are stored into a Mysql database via Hibernate using JPA annotations. So the algorithm does something like this:

- Select from the database the NetworkTargets to be checked (this is actually working)
- Query them (it works)
- Stock CheckpointResults via Hibernate (works with a strange behavior, I'll explain it later).

Actually, a NetworkTarget has several fields and a List of String which models the network protocols that my NetworkTarget offers . I use JPA annotations to map objects:
Code:
@Entity
@Table(name="NetworkTargets")
public class NetworkTarget implements Serializable{
   private String ip;
   private String routerName;
   private String snmpVersion;
   private List<String> services;
   private Set<String> flags;
   private Long id;
...
        @ElementCollection(fetch=FetchType.EAGER)
   @JoinTable(name="NetworkTargetProtocols",joinColumns=@JoinColumn(name="RelatedHostID"))
   @Cascade(CascadeType.PERSIST)
   public List<String> getServices() {
      return services;
   }
     //setter method omitted
...

The NetworkTargets are loaded properly from the database, and I'm able to query them flawlessy.
As you can see, I've got a JoinTable to keep track of the protocols that a NetworkTarget offers.

As soon as the query ends I save some CheckpointResults in my database. CheckpointResult class is made like this:

Code:
@Entity
@Table(name="CheckpointResults")
public class CheckpointResult implements Serializable{
   private Long id;
   private String ip;
   private String startTimestamp;
   private List<String> hostProtocols;
   private List<CheckpointResultMib> protocolMibs;
   private List<CheckpointResultMib> hostMibs;
        ...//related JPA annotations


Now the issue which I find absurd: when I save a CheckpointResult (with a session.save() ) I see in the database schema that all entries from the JoinTable mentioned before are deleted. I've activated the show_sql in my hibernate.cfg.xml, and I noticed that Hibernate issues a delete command on that table, and I sincerely don't know why this happens. Here's a bunch of the sql log I can see:
Quote:

//In this part I fetch my targets
Hibernate: select networktar0_.Id as Id0...
...
2 Target(s) found

//I start saving a CheckpointResult...
Hibernate: insert into JarvisHibernate.CheckpointResults (IP, CheckpointTime) values (?, ?)
Hibernate: insert into JarvisHibernate.RequestedMib (Name, isPointValue) values (?, ?)
Hibernate: insert into JarvisHibernate.MappedMib values ( )

//but then...
Hibernate: delete from JarvisHibernate.NetworkTargetProtocols where RelatedHostID=?
Hibernate: insert into JarvisHibernate.CheckpointedHostMibs (RelatedHost, RequestedHostMibID) values (?, ?)
Hibernate: insert into JarvisHibernate.CheckpointResult_protocols (CheckpointResult_Id, protocols) values (?, ?)
[other successful inserts]
CheckpointResult saved correctly


I was really astonished when I saw it, and I really have no idea about where this delete command can come from. The method which I use to store CheckpointResults is really simple:
Code:
public void createAndStoreCheckpointResult(CheckpointResult result) {
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();
      session.save(result);
      session.getTransaction().commit();
      System.out.println("CheckpointResult saved correctly");
   }


This is a long post, so I'm not gonna make it longer by posting other files, but if there's something that might come useful (such as full JPA annotations, hibernate.cfg.xml and so on), I'll post it as soon as I can. Any suggestions or ideas will be appreciated.
Thanks in advance for any response,
Luca


Last edited by brian_may on Fri Jan 21, 2011 4:30 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Hibernate issues delete commands
PostPosted: Fri Jan 21, 2011 4:29 am 
Newbie

Joined: Thu Jan 13, 2011 3:55 pm
Posts: 4
*bump* No one :)?


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.