Friday, August 1, 2008

XDoclet unsaved-value tag does not work

I am using XDoclet with Hibernate for one of my project. I am wondering why one of the very important tag "unsaved-value" mentioned in the website is not working as expected.

You can see in below code, I have used the tag "unsaved-value" and gave it 0 as value.

/**
* @hibernate.property column="parent_account" type="int" not-null="true" unique="false" unsaved-value="0"
* @return int
*/
public int getParentAccount(){
return parentAccount;
}

In the database, we normally use DEFAULT keyword with any field while creating a database table. This DEFAULT tag tells DB to insert a default mentioned value in case no value for that field, we insert when create a new row in table.

Now when i give unsaved-value as 0 in above XDoclet tags, it should create this property in hbm.xml file something like below-

<property
name="parentAccount"
type="int"
update="true"
insert="true"
column="parent_account"
not-null="true"
unique="false"
default="0"
/>

But this always generate-

<property
name="parentAccount"
type="int"
update="true"
insert="true"
column="parent_account"
not-null="true"
unique="false"
/>

You can see from generated code that default is missing. I am not sure why this tag does not work as expected.

According to XDoclet tag reference, it is-

 
ParameterTypeApplicabilityDescriptionMandatory
unsaved-valuetextA value that distinguishes transient instances with existing persistent state from new transient instances

Default value(s):

null
false
I searched for this tag, but did not find much. I will try to fix this issue. Guys if you have any idea or you faced this problem before then please share here.

Tuesday, July 29, 2008

Too Busy Developing Web Services

It's quite long time I did not write anything in this blog. I was very busy in developing web services for my project. During development, i got many exceptions, but I did not get time to share with you guys. I will be back here after few days and will write few more interesting problems and hopefully the solutions also.

Wednesday, July 2, 2008

Hibernate Cache Problem is still there

In my last post about Hibernate Cache problem, i posted the problem, I was facing with Hibernate. I got many responses in javaranch forum. But none of them seems to be working in my case.

I am still in a hope that i will be able to solve this problem soon. Here are my few conversations with other developers on this problem.

Ques: Hi All,

I have a problem related to hibernate. I have a single database which is being shared by two applications( PHP and Flex ). PHP applications when updates the data in database. Flex application through webservice get this latest data and display accordingly.

The problem here i am facing is because of hibernate cache. my PHP application updates the DB, but webservice returns the old data to flex client.

if i create sessionFactory multiple times, it's not a good solution as it will increase load on my application, so i want to keep it static and want to instantiate only once.

How to let my application to get latest data?

Thanks,

Ans: You don't need a new SessionFactory, just open a new Session. Sessions are cheap to create.

-------------------------------------------

Ques: I think, you did not get my problem, I can create session and later i can close them. That's not an issue. Even after destroying the session, Everytime i get the old data. External application is updating the database and i am not able to get this latest data.

Hope i am clear now. Thanks for replying.

Ans: Opening a new session gets the latest data from the database (unless you are using a second level cache?), so perhaps I don't unerstand the flow of your application? Assuming your PHP app. updates the database, then your Hibernate backed app. opens a session (or flushes an existing open session) and uses that to read from the database it will return the latest data.

If you are using a second level cache you may want ot change your CacheMode, or decide whether you really need a second level cache for these objects?
There was a long conversation. It might be helpful to others.

Thursday, June 26, 2008

Hibernate Cache Problem - A Real Pain

You can follow my hibernate cache problem discussion here at-

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78&t=004126

The problem is that I have a single database which is being shared by two applications (PHP and Flex). PHP applications updates the data in database.
Flex application through webservice try to get this latest data but it always get the old data untill i restart the tomcat server.

I have not added any second level cache implementation in my code and i am also closing the session after my transactions. May be i will get something out from the above discussion on my favourite Javaranch forum.

Sunday, June 22, 2008

Problem org.xml.sax.SAXException: No deserializer for {urn:data} Solved

It was hard time to solve org.xml.sax.SAXException: No deserializer for {urn:data} bug. on the client side, i need to do the mapping for all complex type i used in my web service.

Now the working wsdd file is-

<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="PlaylistService" provider="java:RPC">
<parameter name="className" value="com.xxx.api.playlist.PlaylistService"/>
<parameter name="allowedMethods" value="getPlaylist setPlaylist"/>
<parameter name="wsdlTargetNamespace" value="urn:PlaylistService"/>

<beanMapping qname="ns1:PlaylistRecord"
xmlns:ns1="urn:PlaylistService1"
languageSpecificType="java:com.xxx.container.playlist.PlaylistRecord"/>

<beanMapping qname="ns2:UserRecord"
xmlns:ns2="urn:PlaylistService2"
languageSpecificType="java:com.xxx.container.account.UserRecord"/>

<beanMapping qname="ns3:PlaylistClipRecord"
xmlns:ns3="urn:PlaylistService3"
languageSpecificType="java:com.xxx.container.playlist.PlaylistClipRecord"/>

<beanMapping qname="ns4:playlist.PlaylistParameterRecord"
xmlns:ns4="urn:PlaylistService4"
languageSpecificType="java:com.xxx.container.playlist.PlaylistParameterRecord"/>

<beanMapping qname="ns5:PlaylistClipItemRecord"
xmlns:ns5="urn:PlaylistService5"
languageSpecificType="java:com.xxx.container.playlist.PlaylistClipItemRecord"/>

<beanMapping qname="ns6:PlaylistClipParameterRecord"
xmlns:ns6="urn:PlaylistService6"
languageSpecificType="java:com.xxx.container.playlist.PlaylistClipParameterRecord"/>

<beanMapping qname="ns7:AssetRecord"
xmlns:ns7="urn:PlaylistService7"
languageSpecificType="java:com.xxx.container.asset.AssetRecord"/>

<beanMapping qname="ns8:PlaylistClipItemParameter"
xmlns:ns8="urn:PlaylistService8"
languageSpecificType="java:com.xxx.container.playlist.PlaylistClipItemParameter"/>

</service>

</deployment>


and modified client application is -


Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://192.168.1.151:8080/axis/services/PlaylistService");
call.setOperationName("getPlaylist");

QName qn = new QName("urn:PlaylistService1", "PlaylistRecord");
QName qn1 = new QName("urn:PlaylistService3", "PlaylistClipRecord");
QName qn2 = new QName("urn:PlaylistService5", "PlaylistClipItemRecord");
QName qn3 = new QName("urn:PlaylistService7", "AssetRecord");
QName qn4 = new QName("urn:PlaylistService8", "PlaylistClipItemParameter");
QName qn5 = new QName("urn:PlaylistService6", "PlaylistClipParameterRecord");
QName qn6 = new QName("urn:PlaylistService2", "UserRecord");
QName qn7 = new QName("urn:PlaylistService4", "PlaylistParameterRecord");

call.registerTypeMapping(PlaylistRecord.class, qn,
new org.apache.axis.encoding.ser.BeanSerializerFactory(
PlaylistRecord.class, qn),new org.apache.axis.encoding.ser.BeanDeserializerFactory(
PlaylistRecord.class, qn));

call.registerTypeMapping(PlaylistClipRecord.class, qn1,
new org.apache.axis.encoding.ser.BeanSerializerFactory(
PlaylistClipRecord.class, qn1),new org.apache.axis.encoding.ser.BeanDeserializerFactory(
PlaylistClipRecord.class, qn1));

call.registerTypeMapping(PlaylistClipItemRecord.class, qn2,
new org.apache.axis.encoding.ser.BeanSerializerFactory PlaylistClipItemRecord.class, qn2),new org.apache.axis.encoding.ser.BeanDeserializerFactory(
PlaylistClipItemRecord.class, qn2));

call.registerTypeMapping(AssetRecord.class, qn3,
new org.apache.axis.encoding.ser.BeanSerializerFactory(
AssetRecord.class, qn3),new org.apache.axis.encoding.ser.BeanDeserializerFactory(
AssetRecord.class, qn3));

call.registerTypeMapping(PlaylistClipItemParameter.class, qn4,
new org.apache.axis.encoding.ser.BeanSerializerFactory(
PlaylistClipItemParameter.class, qn4),new org.apache.axis.encoding.ser.BeanDeserializerFactory(
PlaylistClipItemParameter.class, qn4));

call.registerTypeMapping(PlaylistClipParameterRecord.class, qn5,
new org.apache.axis.encoding.ser.BeanSerializerFactory(
PlaylistClipParameterRecord.class, qn5),new org.apache.axis.encoding.ser.BeanDeserializerFactory(
PlaylistClipParameterRecord.class, qn5));

call.registerTypeMapping(UserRecord.class, qn6,
new org.apache.axis.encoding.ser.BeanSerializerFactory(
UserRecord.class, qn6),new org.apache.axis.encoding.ser.BeanDeserializerFactory(
UserRecord.class, qn6));

call.registerTypeMapping(PlaylistParameterRecord.class, qn7,
new org.apache.axis.encoding.ser.BeanSerializerFactory(
PlaylistParameterRecord.class, qn7),new org.apache.axis.encoding.ser.BeanDeserializerFactory(
PlaylistParameterRecord.class, qn7));

call.addParameter("id", XMLType.XSD_INT, ParameterMode.IN);
call.addParameter("credential", XMLType.XSD_STRING, ParameterMode.IN);

call.setReturnType(XMLType.SOAP_ARRAY);

PlaylistRecord[] output = (PlaylistRecord[]) call.invoke(new Object[] { 1, "9b4af867274d1f95f222bfb27d05a86" });


Now i have register here all complex types I used in .wsdd file. It took so much time to solve this exception. Finally it's working.

Friday, June 20, 2008

org.xml.sax.SAXException: No deserializer for {urn:data}

Jun 20, 2008 12:26:53 PM org.apache.axis.client.Call invoke
SEVERE: Exception:
org.xml.sax.SAXException: No deserializer for {urn:data}com.xxx.container.pl
aylist.PlaylistRecord
at org.apache.axis.encoding.DeserializerImpl.onStartElement(Deserializer
Impl.java:453)
at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerIm
pl.java:393)
at org.apache.axis.encoding.DeserializationContext.startElement(Deserial
izationContext.java:1048)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.ja
va:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElemen
t.java:1141)
at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerIm
pl.java:369)
at org.apache.axis.encoding.DeserializationContext.startElement(Deserial
izationContext.java:1048)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.ja
va:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElemen
t.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at PlaylistClient.testMethod(PlaylistClient.java:66)
at PlaylistClient.main(PlaylistClient.java:80)
Inside Main: +; nested exception is:
org.xml.sax.SAXException: No deserializer for {urn:data}com.xxx.cont
ainer.playlist.PlaylistRecord


It's taking my so much time and i am not able to figure out what is the problem actually. I have worked with complex types in Axis but this time why it's asking for deserializer.

my WSDD file is-

<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="PlaylistService" provider="java:RPC">
<parameter name="className" value="com.xxx.api.playlist.PlaylistService"/>
<parameter name="allowedMethods" value="getPlaylist setPlaylist"/>

<beanMapping qname="ns:com.xxx.container.playlist.PlaylistRecord"
xmlns:ns="urn:data"
languageSpecificType="java:com.xxx.container.playlist.PlaylistRecord"/>

<beanMapping qname="ns:com.xxx.container.account.UserRecord"
xmlns:ns="urn:data"
languageSpecificType="java:com.xxx.container.account.UserRecord"/>

<beanMapping qname="ns:com.xxx.container.asset.AssetRecord"
xmlns:ns="urn:data"
languageSpecificType="java:com.xxx.container.asset.AssetRecord"/>

beanMapping qname="ns:com.xxx.container.playlist.PlaylistClipItemParameter"
xmlns:ns="urn:data"
languageSpecificType="java:com.xxx.container.playlist.PlaylistClipItemParameter"/>

<beanMapping qname="ns:com.xxx.container.playlist.PlaylistClipItemRecord"
xmlns:ns="urn:data"
languageSpecificType="java:com.xxx.container.playlist.PlaylistClipItemRecord"/>

<beanMapping qname="ns:com.xxx.container.playlist.PlaylistClipParameterRecord"
xmlns:ns="urn:data"
languageSpecificType="java:com.xxx.container.playlist.PlaylistClipParameterRecord"/>

<beanMapping qname="ns:com.xxx.container.playlist.PlaylistClipRecord"
xmlns:ns="urn:data"
languageSpecificType="java:com.xxx.container.playlist.PlaylistClipRecord"/>

<beanMapping qname="ns:com.xxx.container.playlist.PlaylistParameterRecord"
xmlns:ns="urn:data"
languageSpecificType="java:com.xxx.container.playlist.PlaylistParameterRecord"/>

</service>

</deployment>


and my client is-

String targetNamespace = "PlaylistService";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://localhost:8080/axis/services/PlaylistService");
call.setOperationName("getPlaylist");

QName qn = new QName("urn:data", "PlaylistRecord");

call.registerTypeMapping(PlaylistRecord.class, qn,
new org.apache.axis.encoding.ser.BeanSerializerFactory(
PlaylistRecord.class, qn),
new org.apache.axis.encoding.ser.BeanDeserializerFactory(
PlaylistRecord.class, qn));

call.addParameter("id", XMLType.XSD_INT, ParameterMode.IN);
call.addParameter("credential", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.SOAP_ARRAY);

PlaylistRecord[] output = (PlaylistRecord[]) call.invoke(new Object[] { 1, "b9e9bd267d6f4ef3885cfd71f42ff059" });

System.out.println(output);


No idea what is wrong here. Help me guys...

Wednesday, June 18, 2008

- SQL Error: 0, SQLState: S1009

Hibernate: select this_.id as id0_, this_.clip_data_id as clip2_15_0_, this_.item_type as item3_15_0_, this_.content as content15_0_, this_.status as status15_0_, this_.ins_time as ins6_15_0_, this_.up_time as up7_15_0_ from item_data this_ where this_.clip_data_id=?

- SQL Error: 0, SQLState: S1009

- Invalid value for getInt() - 'video'

Exception: org.hibernate.exception.GenericJDBCException: could not execute query


In my bean file, i put "int" in place of "string"

/**
* @hibernate.property column="item_type" type="int" not-null="true" unique="false" unsaved-value="video"
* @return String
*/
public String getItemType(){
return itemType;
}

This was the problem, the type was "string" and i put it "int" by mistake. I corrected it to-

/**
* @hibernate.property column="item_type" type="string" not-null="true" unique="false" unsaved-value="video"
* @return String
*/
public String getItemType(){
return itemType;
}

And the exception was no more.

Latest Posts

Latest Comments