-->
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.  [ 9 posts ] 
Author Message
 Post subject: cache
PostPosted: Wed Feb 08, 2006 8:33 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:

<hibernate-mapping>
<class name="WebUser" table="webuser">

<id name="userID" column="userID" type="int">
<generator class="native"/>
</id>

<property name="userName" column="userName" type="string" unique="true" not-null="true" access="field"/>
<property name="userRealName" column="userRealName" not-null="true" type="string" access="field"/>
<property name="userPassword" column="userPassword" not-null="true" type="string" access="field"/>


</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: MySql 4.0.15

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

First of all sorry for my english.

I have some problems with the caching. Above you see the mapping document of WebUser class. As you can see there is no relation from WebUser to the other classes, also there is no relation from other classes to the WebUser.

I disable the second-level cache by
<property name="hibernate.cache.use_second_level_cache">false</property>

in the hibernate.cfg.xml file.

Problem: I start my application. i get the web users from database while starting the application. then i delete one web user record from the database. then i list the web users from my application and see that the deleted record is still here. What can i do the handle this situation?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 11:27 am 
Beginner
Beginner

Joined: Tue Feb 01, 2005 5:26 pm
Posts: 24
Location: dallas
increase the logging level on hibernate and see if caching is disabled or enabled.

dont forget to rate if this posting helps you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 4:02 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
i look at the logs and see that second-level and query caches are disabled.

it seems hibernate read these values from somewhere else. because i see the entries that i delete from the database (as i said i use MySql and i use MySql control center to delete entries) in my application.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 9:29 am 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
We need to know how you do you load your users, and then how do get the user you have deleted.
Are doing the two operations in a single Session ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 8:22 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
to make thing clear i give some basic example below:

*****************************************
my hibernate.cfg.xml

<session-factory>
<property name="connection.username">
root
</property>
<property name="connection.url">
jdbc:mysql://localhost/mydatabaseuseUnicode=true&amp;characterEncoding=UTF-8
</property>
<property name="dialect">
org.hibernate.dialect.MySQLInnoDBDialect
</property>
<property name="connection.password">
123456
</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.cache.use_second_level_cache">
false
</property>

<mapping resource="Address.hbm.xml"/>

</session-factory>
*****************************************

Address.hbm.xml

<hibernate-mapping>

<class name="caching.disabled.Address"
table="address">

<id type="java.lang.Integer" column="id">
<generator class="increment" />
</id>

<property
name="zipCode"
type="java.lang.String"
column="zipCode">
</property>
<property
name="street"
type="java.lang.String"
column="street">
</property>

</class>
</hibernate-mapping>
*****************************************

Address.java

public class Address {

private String zipCode;
private String city;
private String street;

public Address() {
}
public Address(String zipCode,String city,String street){
this.zipCode = zipCode;
this.city = city;
this.street = street;
}
public String getCity() {
return city;
}
public String getStreet() {
return street;
}
public String getZipCode() {
return zipCode;
}
public void setCity(String city) {
this.city = city;
}
public void setStreet(String street) {
this.street = street;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
}
*****************************************

Test.java --> this class contains the main function. here you see two functions. saveAddress saves one address at a time, and listAddress lists the addresses in the database.

public void saveAddress(Address address){
Session session = null;
Transaction tx = null;

try {
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
session.save(address);
tx.commit();
session.close();
System.out.println("Address kaydedildi");
}
catch (Exception e) {
e.printStackTrace();
}
}



public void listAddresses(){
List list = null;
Session session;
try {
session = HibernateSessionFactory.currentSession();
session.setCacheMode(CacheMode.PUT);
list = session.createQuery("from "+"Address").list();
Iterator iter = list.iterator();
while(iter.hasNext())
{
Address address = (Address) iter.next();
System.out.println(address.getCity());
}
session.close();
}
catch(HibernateException he) {
he.printStackTrace();
}
catch(DAOException de) {
de.printStackTrace();
}
***************************************************

Here is my problem, first i call saveAddress for n times. then i open the database and delete the records. and then i call listAddresses. what i want is to see 0 records. but hibernate read from somewhere else and listAddresses function returns me the all deleted records.

My question is? where hibernate caches these data. and how can i disable it?

by the way as you can see i disable the second-level-cache.

thnx for help.


Last edited by e120281 on Mon Feb 13, 2006 8:57 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 8:32 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Commit transaction before "close".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 8:59 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
baliukas i commit the transaction before closing the session.

Not: there was some extra session.close statetment i deleted it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 9:11 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Code:
while(iter.hasNext())
{
Address address = (Address) iter.next();
System.out.println(address.getCity());
}
session.close();
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 9:48 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 4:22 am
Posts: 24
i am sorry man, i didnot realize it.

thnx for help...


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