maybe my problem is related to http://code.google.com/p/google-web-toolkit/issues/detail?id=4140
The gwt remote call to the following service works for getUser1() but
fails for getUser2():
@Service("testService")
public class TestServiceImpl implements TestService {
public User getUser1() {
User u = new User();
u.setGroups(new HashSet<Group>());
u.setId(0);
u.setPassword("pw");
u.setUsername("name");
return u;
}
public User getUser2() {
return new User();
}
}
User is a simple JPA annotated entity. I'm using gwt 2.0.3, JPA 2,
spring 3.0.1 and the GWTSpringController of gwt-sl 1.0. Before
switching to gwt 2.0 everything worked fine.
This is the exception thrown:
Something other than an int was returned from JSNI method
'@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::readInt()':
JS value of type undefined, expected int
com.google.gwt.dev.shell.HostedModeException: Something other than an
int was returned from JSNI method
'@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::readInt()':
JS value of type undefined, expected int at
com.google.gwt.dev.shell.JsValueGlue.getIntRange(JsValueGlue.java:266)
at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:144) at
com.google.gwt.dev.shell.ModuleSpace.invokeNativeInt(ModuleSpace.java:
242) at
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeInt(JavaScriptHost.java:
75) at
com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader.readInt(ClientSerializationStreamReader.java)
at
com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader.readString(ClientSerializationStreamReader.java:
107) at
net.anwaltsdatenbank.adb.client.domain.jforum.User_FieldSerializer.deserialize(User_FieldSerializer.java:
42) (...)
Hope someone can help here.
Thus : "Something other than an int was returned from JSNI method"
That "something other" might have been a null.
On Mar 1, 5:38 am, tekbe <tim_ehl...@gmx.de> wrote:
> Hi,
>
> maybe my problem is related tohttp://code.google.com/p/google-web-toolkit/issues/detail?id=4140
>
> The gwt remote call to the following service works for getUser1() but
> fails for getUser2():
>
> @Service("testService")
> public class TestServiceImpl implements TestService {
>
> public User getUser1() {
> User u = new User();
> u.setGroups(new HashSet<Group>());
> u.setId(0);
> u.setPassword("pw");
> u.setUsername("name");
> return u;
> }
>
> public User getUser2() {
> return new User();
> }
>
> }
>
> User is a simple JPA annotated entity. I'm using gwt 2.0.3, JPA 2,
> spring 3.0.1 and the GWTSpringController of gwt-sl 1.0. Before
> switching to gwt 2.0 everything worked fine.
>
> This is the exception thrown:
>
> Something other than an int was returned from JSNI method
> '...@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::readI nt()':
> JS value of type undefined, expected int
> com.google.gwt.dev.shell.HostedModeException: Something other than an
> int was returned from JSNI method
> '...@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::readI nt()':
When switching back to gwt 1.7.3 the very same example works.
Can someone please tell if this is a bug or a feature? And if this is
a feature, why did the behaviour change?
thanks.
//I'm a noob, since few moths into Java
changin' variables type from int to Integer should solve the issue ...
The Integer wrapper is safe to be null (default value when
initialized) and valid.
You can also change all the other variable's primitive types
example:boolean -->Boolean
I hope I have got the point.
Regards
I'm using firefox 3.5.2 with the gwt developer plugin 1.0.7511
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import net.anwaltsdatenbank.adb.client.domain.PersistedEntity;
@Entity
@Table(name = "users")
public class User implements PersistedEntity<Integer> {
private static final long serialVersionUID = 762298174599256998L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "user_id")
private Integer id;
@Column(name = "username")
private String username;
@Column(name = "user_password")
private String password;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "user_groups", joinColumns = @JoinColumn(name =
"user_id"), inverseJoinColumns = @JoinColumn(name = "group_id"))
private Set<Group> groups;
public User(String username, String password) {
super();
this.username = username;
this.password = password;
}
public User() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Set<Group> getGroups() {
return groups;
}
public void setGroups(Set<Group> groups) {
this.groups = groups;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
And the PersistedEntity Interface:
import java.io.Serializable;
import com.google.gwt.user.client.rpc.IsSerializable;
public interface PersistedEntity<KEYTYPE> extends Serializable,
IsSerializable {
KEYTYPE getId();
}
I don't have a solution to your problem, but since you aren't even
persisting user2 with the entity manager, will the JPA annotations
even apply? Isn't it just a POJO until you do that - maybe you can try
it with a similar object without any JPA annotations!
Chris
On Feb 28, 10:38 pm, tekbe <tim_ehl...@gmx.de> wrote:
> Hi,
>
> maybe my problem is related tohttp://code.google.com/p/google-web-toolkit/issues/detail?id=4140
>
> The gwt remote call to the following service works for getUser1() but
> fails for getUser2():
>
> @Service("testService")
> public class TestServiceImpl implements TestService {
>
> public User getUser1() {
> User u = new User();
> u.setGroups(new HashSet<Group>());
> u.setId(0);
> u.setPassword("pw");
> u.setUsername("name");
> return u;
> }
>
> public User getUser2() {
> return new User();
> }
>
> }
>
> User is a simple JPA annotated entity. I'm using gwt 2.0.3, JPA 2,
> spring 3.0.1 and the GWTSpringController of gwt-sl 1.0. Before
> switching to gwt 2.0 everything worked fine.
>
> This is the exception thrown:
>
> Something other than an int was returned from JSNI method
> '...@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::readI nt()':
> JS value of type undefined, expected int
> com.google.gwt.dev.shell.HostedModeException: Something other than an
> int was returned from JSNI method
> '...@com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::readI nt()':
> JS value of type undefined, expected int at
> com.google.gwt.dev.shell.JsValueGlue.getIntRange(JsValueGlue.java:266)
> at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:144) at
> com.google.gwt.dev.shell.ModuleSpace.invokeNativeInt(ModuleSpace.java:
> 242) at
> com.google.gwt.dev.shell.JavaScriptHost.invokeNativeInt(JavaScriptHost.java :
> 75) at
> com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader.readInt (ClientSerializationStreamReader.java)
> at
> com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader.readStr ing(ClientSerializationStreamReader.java:
> 107) at
> net.anwaltsdatenbank.adb.client.domain.jforum.User_FieldSerializer.deserial ize(User_FieldSerializer.java:
in the following example getUser1(), getUser3() and getUser4() work,
getUser2() fails...
@Service("testService")
public class TestServiceImpl implements TestService {
public User getUser1() {
User u = new User();
u.setGroups(new HashSet<Group>());
u.setId(0);
u.setPassword("pw");
u.setUsername("name");
return u;
}
public User getUser2() {
return new User();
}
public User2 getUser3() {
User2 u = new User2();
u.setGroups(new HashSet<Group>());
u.setId(0);
u.setPassword("pw");
u.setUsername("name");
return u;
}
public User2 getUser4() {
return new User2();
}
}
As a workaround I could use data transfer objects in the real
services. Maybe it's a good idea anyway.
yes, I assume, it may have something to do with this:
GWT assumes, your object is an Enhanced Class, because it's annotated
with @Entity. This may be a wrong assumption in this case (is it?)
So you could also try to persist the object in getUser2() with the
entity manager, then detach it, and see if that works. Would be very
interesting!
BTW, I do actually believe, that it's a good idea to have data
transfer objects - even if it's redundant work (which I generally
don't like very much), but it also makes it possible to fine-tune
what's transferred over the wire. So if you have to save on bandwidth
(I do), it's a good way to go anyway :-) It can also save you from a
lot of headache...
Chris
On Mar 2, 9:38 pm, Chris Lercher <cl_for_mail...@gmx.net> wrote:
> It can also save you from a
> lot of headache...
PS especially, if someone in your team later introduces confidential/
identifying/... data in the Entity - which can be perfectly ok, but
turns into a maximum credible accident, if unintentionally transferred
to the browser...
I'm not sure this really means that the JPA 2 annotated entities have
to be enhanced to be serializable. If such an entity is created on the
client and then sent to the server to be persisted, it's not enhanced
of course. And this also can cause funny errors:
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/b9237c5638b68a04/c6d888a1ac444d28
For unenhancing the entities I used the Hibernate3BeanReplicator of
the beanlib library. With it it's possible to configure a whitelist of
classes and attributes which should be serialized to the client. So
additional confidental information in the domain model would not be
harmful. The problem would rather be the deserialization (sending the
objects back to the server): Then one has to do some kind of merging
where the information which was'nt sent to the client must be loaded
from the database and the rest is overwritten from the data received
from the client. afaik this kind of merging cannot be done
automatically with the beanlib. Considering this, it's really best to
use data transfer objects, thus making the information which is sent
to the client more explicit.
I thought this was a technical problem, but it turns out to be
conceptional / architectural :-)
The problem with serializing uninitialized objects occurs with firefox
3.5.2 on suse 11.1 with developer plugin version 1.0.7511.
To resolve the problem for serialization type i have used Apache Dozer
Framework.
Without dozer i have the serialization error relative to
PersistenceBag for hibernate.
Regards
On 2 Mar, 10:13, tekbe <tim_ehl...@gmx.de> wrote:
> I noticed theproblemI described above only occurs in development
> mode. Thankfully null is still serializable in server mode with gwt
> 2.0.3 ;)
>
> Theproblemwith serializinguninitializedobjects occurs with firefox
> 3.5.2on suse 11.1 with developer plugin version 1.0.7511.