-->
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: Can not save
PostPosted: Wed Jan 16, 2008 5:24 pm 
Newbie

Joined: Wed Jan 16, 2008 4:55 pm
Posts: 4
I 'm having problem saving object to the database. When I save an
object by invoking the save and commit method it saves it and am able
to view however when I close the application and start it again, the
saved details are not there.

Do you have any idea about what is the problem?

Thank you very much in advance.

Hibernate version 3.0


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 3:08 am 
Newbie

Joined: Tue Aug 28, 2007 3:18 am
Posts: 13
Can u please give teh example of your POJO and mapping.xml

After saving, did u go to the Db and see that the data is persisted / not ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 3:40 am 
Newbie

Joined: Wed Jan 16, 2008 4:55 pm
Posts: 4
tamal123 wrote:
Can u please give teh example of your POJO and mapping.xml

After saving, did u go to the Db and see that the data is persisted / not ?


Yes, after saving and closing the app I saw the DB and it was ok. An example is the next one:

public class Dimension {

private String nombreDim;

private String descripcionDim;

private Ambito ambitoDim;

private Enfoque enfoqueDim;

private Set<Variable> variables;

public Enfoque getEnfoqueDim() {
return enfoqueDim;
}

public void setEnfoqueDim(Enfoque enfoqueDim) {
this.enfoqueDim = enfoqueDim;
}

public Ambito getAmbitoDim() {
return ambitoDim;
}

public void setAmbitoDim(Ambito ambitoDim) {
this.ambitoDim = ambitoDim;
}

public String getDescripcionDim() {
return descripcionDim;
}

public void setDescripcionDim(String descripcionDim) {
this.descripcionDim = descripcionDim;
}

public String getNombreDim() {
return nombreDim;
}

public void setNombreDim(String nombreDim) {
this.nombreDim = nombreDim;
}

public Set<Variable> getVariables() {
return variables;
}

public void setVariables(Set<Variable> variables) {
this.variables = variables;
}
}

and

<class name="model.Dimension" table="DIMENSIONES">
<id name="nombreDim" column="NOMBRE_DIM"/>
<property name="descripcionDim"/>
<property name="ambitoDim"/>
<property name="enfoqueDim"/>
<set name="variables" table="DIMENSION_VARIABLES">
<key column="NOMBRE_DIM"/>
<one-to-many class="model.Variable"/>
</set>
</class>

and also in hibernate.cfg.xml

<property name="hbm2ddl.auto">update</property>

Do you have any idea? Thank you very much, it's really important!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 4:59 am 
Newbie

Joined: Tue Aug 28, 2007 3:18 am
Posts: 13
Sorry, Actually,
I have to ask u more specifically,

b sure that u r not running any SQL operation outside ur hibernate operation.
b sure that u r not running delete()

then u can track the database regarding at what point the data is getting deleted. I think u can detect it urself.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 5:53 am 
Newbie

Joined: Wed Jan 16, 2008 4:55 pm
Posts: 4
tamal123 wrote:
Sorry, Actually,
I have to ask u more specifically,

b sure that u r not running any SQL operation outside ur hibernate operation.
b sure that u r not running delete()

then u can track the database regarding at what point the data is getting deleted. I think u can detect it urself.


First of all thanks for attention.

The question is that in the first part of my app I insert all the basic data, using .saveOrUpdate. The DB is configured with UPDATE so I don't have all the data repeated.

The problem is that my app lets the user change this basic data. So the next time I run the app, the details of the basic data are charge. I have supposed that if I'm using saveOrUpdate, it will mantain the modifications that the user has done. But that's not what happens....

I hope that you could understant my problem... Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 7:11 am 
Newbie

Joined: Tue Aug 28, 2007 3:18 am
Posts: 13
OK..
I think I got ur problem.

If you use simple Update() or SaveOrUpdate()
in any case, ONLY populated properties of POJO are getting updated in DB.

To retain your Data,
2 ways :

1. Persist all the values of POJO throught the application.means DB ->DAO ->SERVICE -> FRONTEND and also FRONTEND -> SERVICE -> DAO -> DB

If that not possible

then

2. before updating POJO , make a SELECT , populate fields frm DB object to ur POJO (coming from service). Then update ur POJO.

3. Keep the Sesion open until ur pojo returnd back for updating.

Dont Forget to add credit if it helps u.. ;)[/img]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 8:22 am 
Newbie

Joined: Wed Jan 16, 2008 4:55 pm
Posts: 4
THANKS!!!!!! It really worked

You have saved my Degree Project ;)


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.