Hi all. I have a urgent task with Webservice and Hibernate. And now i meet a very strange problem with My Demo. Please help me.
I describe them fllowing :
I make a Server WebService and Client App.
i deploy my server on Glassfish and run Client App to connect and call methods of Server. i runs well
But when i change something on database manually... i run again my client app, it can rot read some new data on database. It still show old data.
Only when i retart my Server Application, my client can read new database wihch i have just updated.
To seem that i have problem with Cache right ?
Please see my source codes with Both Server and Client Side.
SERVER SIDE :
My Table Database
CREATE TABLE /*!32312 IF NOT EXISTS*/ `testtable` (
`id` int(5) unsigned NOT NULL,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Hibernate file
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost:3306/cmfapp</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">MySql</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>
<mapping resource="cmf/com/Testtable.hbm.xml" />
</session-factory>
</hibernate-configuration>
TestTableDao... Where defines some methods which client will call...
public class TesttableDAO {
public static final String NAME = "name";
public List<Testtable> findAll() {
try {
String queryString = "from Testtable";
Query queryObject = HibernateSessionFactory.getSession().createQuery(queryString);
HibernateSessionFactory.getSession().flush();
return queryObject.list();
} catch (RuntimeException re) {
throw re;
}
}
}
TesttableDAODelegate....
@javax.jws.WebService(targetNamespace = "http://com.cmf/", serviceName = "TesttableDAOService", portName = "TesttableDAOPort", wsdlLocation = "WEB-INF/wsdl/TesttableDAOService.wsdl")
public class TesttableDAODelegate {
cmf.com.TesttableDAO testtableDAO = new cmf.com.TesttableDAO();
public List<Testtable> findAll() {
return testtableDAO.findAll();
}
}
I deploy on Glassfish successfully.
CLIENT SIDE These code is automatically genereated by My Eclipse... Please see
TesttableDAOService class
@WebServiceClient(name = "TesttableDAOService", targetNamespace = "http://com.cmf/", wsdlLocation = "http://localhost:8070/testweb/TesttableDAOService?WSDL")
public class TesttableDAOService extends Service {
public static void main(String[] args) {
System.out.println(new TesttableDAOService().getTesttableDAOPort().findAll().get(0).getName());
}
private final static URL TESTTABLEDAOSERVICE_WSDL_LOCATION;
static {
URL url = null;
try {
URL baseUrl;
baseUrl = cmf.com.TesttableDAOService.class.getResource(".");
url = new URL(baseUrl,
"http://localhost:8070/testweb/TesttableDAOService?WSDL");
} catch (MalformedURLException e) {
}
TESTTABLEDAOSERVICE_WSDL_LOCATION = url;
}
public TesttableDAOService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public TesttableDAOService() {
super(TESTTABLEDAOSERVICE_WSDL_LOCATION, new QName("http://com.cmf/",
"TesttableDAOService"));
}
@WebEndpoint(name = "TesttableDAOPort")
public TesttableDAODelegate getTesttableDAOPort() {
return super.getPort(new QName("http://com.cmf/", "TesttableDAOPort"),
TesttableDAODelegate.class);
}
}
Testtable class
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "testtable", propOrder = { "id", "name" })
public class Testtable {
protected Integer id;
protected String name;
public Integer getId() {
return id;
}
public void setId(Integer value) {
this.id = value;
}
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
}
TesttableDAODelegate class
@WebService(name = "TesttableDAODelegate", targetNamespace = "http://com.cmf/")
public interface TesttableDAODelegate {
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "findAll", targetNamespace = "http://com.cmf/", className = "cmf.com.FindAll")
@ResponseWrapper(localName = "findAllResponse", targetNamespace = "http://com.cmf/", className = "cmf.com.FindAllResponse")
public List<Testtable> findAll();
}
FindAll class
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "findAll")
public class FindAll {
}
FindAllResponse class
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "findAllResponse", propOrder = { "_return" })
public class FindAllResponse {
@XmlElement(name = "return")
protected List<Testtable> _return;
public List<Testtable> getReturn() {
if (_return == null) {
_return = new ArrayList<Testtable>();
}
return this._return;
}
}
package-info class
@javax.xml.bind.annotation.XmlSchema(namespace = "http://com.cmf/")
package cmf.com;
ObjectFactory class
@XmlRegistry
public class ObjectFactory {
private final static QName _FindAll_QNAME = new QName("http://com.cmf/",
"findAll");
private final static QName _FindAllResponse_QNAME = new QName(
"http://com.cmf/", "findAllResponse");
public ObjectFactory() {
}
public FindAll createFindAll() {
return new FindAll();
}
public Testtable createTesttable() {
return new Testtable();
}
public FindAllResponse createFindAllResponse() {
return new FindAllResponse();
}
@XmlElementDecl(namespace = "http://com.cmf/", name = "findAll")
public JAXBElement<FindAll> createFindAll(FindAll value) {
return new JAXBElement<FindAll>(_FindAll_QNAME, FindAll.class, null,
value);
}
@XmlElementDecl(namespace = "http://com.cmf/", name = "findAllResponse")
public JAXBElement<FindAllResponse> createFindAllResponse(
FindAllResponse value) {
return new JAXBElement<FindAllResponse>(_FindAllResponse_QNAME,
FindAllResponse.class, null, value);
}
}
Please help me
Thanks in advance
Diego