-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to save the Entity member ?
PostPosted: Fri Feb 13, 2009 12:13 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
Hello,

I have a new problem... :(

In fact, I have a class (@Entity) with some member data like this :
Code:
@Entity
public class Dossier implements Serializable {
   


   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Integer id;
        @CollectionOfElements
   private List<Document> documents;
   private String idCompatibilite;

   private String numPolice;

   @CollectionOfElements(fetch = FetchType.EAGER)
   @Fetch(FetchMode.SUBSELECT)
   @Cascade(value = CascadeType.ALL)
   private List<Signature> protagonistes;
...


I look on the forum for a moment so I ask you : why when I use session.saveOrUpdate(dossier), the member protagoniste is not saved ?

This is the sql query which is executed :
Code:
Save Dossier
17:09:14,427 DEBUG SQL:111 - update Dossier set  idCompatibilite=?,  numPolice=?,  OPTLOCK=?, wan=? where id=? and OPTLOCK=?
Hibernate: update Dossier set idCompatibilite=?, numPolice=? OPTLOCK=?, where id=? and OPTLOCK=?
17:09:14,427 DEBUG SQL:111 - delete from Dossier_Document where Dossier_id=?
Hibernate: delete from Dossier_Document where Dossier_id=?


I do not understand why there is a delete operation and why protagonistes list does not appears in query ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 12:22 pm 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Code:
public class Dossier implements Serializable {
   


   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Integer id;

        @CollectionOfElements
        //Add This MAPPING ALSO
    @JoinTable(name="table_name_for_Document",joinColumns=@JoinColumn(name="Foreigh_key_column_in_DOCUMENT_Table"))

   private List<Document> documents;
   private String idCompatibilite;

   private String numPolice;

   @CollectionOfElements(fetch = FetchType.EAGER)
   @Fetch(FetchMode.SUBSELECT)
   @Cascade(value = CascadeType.ALL)
   private List<Signature> protagonistes;
...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 12:42 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
Ok the delete query disapear, but the data are not saved.

This is my new code :
Code:
...
@CollectionOfElements   @JoinTable(name="dossier_document_join",joinColumns=@JoinColumn(name="file"))
private List<Document> documents;

...
@CollectionOfElements(fetch = FetchType.EAGER)   @JoinTable(name="dossier_prota")
   @Cascade(value = CascadeType.ALL)
   private List<Signature> protagonistes;
...


This is the query when I save :
Code:
17:47:08,103 DEBUG SQL:111 - update Dossier set codeGestionnaire=?, dateMission=?, declarationSinistre=?, descriptifDommage=?, etatDossier=?, idCompatibilite=?, adresse=?, codePostal=?, ville=?, natureMission=?, numDarvaDest=?, numDarvaExp=?, numMission=?, numPolice=?, sinistre=?, typeLieu=?, OPTLOCK=?, wan=? where id=? and OPTLOCK=?
Hibernate: update Dossier set codeGestionnaire=?, dateMission=?, declarationSinistre=?, descriptifDommage=?, etatDossier=?, idCompatibilite=?, adresse=?, codePostal=?, ville=?, natureMission=?, numDarvaDest=?, numDarvaExp=?, numMission=?, numPolice=?, sinistre=?, typeLieu=?, OPTLOCK=?, wan=? where id=? and OPTLOCK=?
...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 1:14 pm 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Code:
CollectionOfElements   @JoinTable(name="dossier_document_join",joinColumns=@JoinColumn(name="file"))
private List<Document> documents;

...
@CollectionOfElements(fetch = FetchType.EAGER)   @JoinTable(name="dossier_prota") // define also joinColumn attribute of this annotation
   @Cascade(value = CascadeType.ALL) //REMOVE THIS. This is not required here as you are mapping it as a Component
   private List<Signature> protagonistes;


Could you can post the code of Signature and Document class also


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 4:53 am 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
I update the remove you say, but I can still save the protagoniste values ...? And it seems to have a delete operation about the file ?

Code:
Save Dossier
09:48:54,323 DEBUG SQL:111 - update Dossier set codeGestionnaire=?, dateMission=?, declarationSinistre=?, descriptifDommage=?, etatDossier=?, idCompatibilite=?, adresse=?, codePostal=?, ville=?, natureMission=?, numDarvaDest=?, numDarvaExp=?, numMission=?, numPolice=?, sinistre=?, typeLieu=?, OPTLOCK=?, wan=? where id=? and OPTLOCK=?
Hibernate: update Dossier set codeGestionnaire=?, dateMission=?, declarationSinistre=?, descriptifDommage=?, etatDossier=?, idCompatibilite=?, adresse=?, codePostal=?, ville=?, natureMission=?, numDarvaDest=?, numDarvaExp=?, numMission=?, numPolice=?, sinistre=?, typeLieu=?, OPTLOCK=?, wan=? where id=? and OPTLOCK=?
09:48:54,323 DEBUG SQL:111 - delete from dossier_document_join where file=?
Hibernate: delete from dossier_document_join where file=?
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 6:31 am 
Beginner
Beginner

Joined: Wed Jan 28, 2009 10:16 am
Posts: 37
In fact, there is something I do not understand. When you have a object with an Id that you want hibernate initialise automaticly, when you create an instance of this object, the id is null ! But it is only when the object is saved that hibernate decides to attribute a value using :
select nextval ('hibernate_sequence') ??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 8:21 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
If the id values are being generated by the database, then it makes sense that Hibernate should defer assigning an id until the entity is persisted.

I believe there are other id generation approaches which will not rely on the database - so, technically speaking it is not a Hibernate issue for all generators.

--
Stephen Souness


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