[appengine-java] Re: JDO problem : oid is not instanceof javax.jdo.identity.ObjectIdentity

2010-10-13 Thread l.denardo
To make clearer what I mean with "not predictable", I post part of a
test method:

[...]
try{
pm.makePersistent(persistent);
saved = persistent.getKey();
}
finally{

pm.close();
}
[...]
If I run the test, it fails.

If I modify *just that* portion of code stating

[...]
try{
pm.makePersistent(persistent);
saved = persistent.getKey();
}
finally{
if (pm.currentTransaction().isActive()){
pm.currentTransaction().rollback();
}
pm.close();
}
[...]

And run the test again (nothing else changes in my JUnit test nor in
data model), it passes.
If i run again the test (no further code modifications) it fails like
the first time.

This may be a problem in my test configurations, I guess.If this can
help, general config for my unit test is

private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new
LocalDatastoreServiceTestConfig());

private static final PersistenceManagerFactory pmf =
JDOHelper.getPersistenceManagerFactory("transactions-optional");

@Before
public void setUp() throws Exception {
helper.setUp();
}

@After
public void tearDown() throws Exception {
helper.tearDown();
}

Hope this can better identify the issue.

Regards
Lorenzo

On Oct 13, 12:21 pm, "l.denardo"  wrote:
> Hello everybody,
> I'm facing a really annoying issue which I stepped into.
>
> My unit tests (JDO) sometimes throw a
> ClassCastException: oid is not instanceof
> javax.jdo.identity.ObjectIdentity
>
> The most annoying fact is that this is not reproducible in a
> predictable way.
> The very same JUnit test (using the App Engine testing suite) throws
> this error, then stops, then throws it again.
>
> I got this error for a while, tried to set up a simpler data model to
> reproduce it, without success (all tests on simplified model passed
> without errors).
> Then i re-run the failed test, and it completed successfully *without
> any code modifications*.
>
> Looks like this behavior is difficult to reproduce and appears to
> happen quite 
> randomly:http://groups.google.com/group/google-appengine-java/browse_thread/th...
>
> If anyone has advice about the reasons for this behavior, it would be
> a great help.
> It makes testing a data model unreliable, so I would like to
> understand if this is a bug in the test cases or something due to
> particular data models, to modify my classes accordingly.
>
> Thanks for your help
> Lorenzo

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: JDO problem : oid is not instanceof javax.jdo.identity.ObjectIdentity

2010-10-13 Thread l.denardo
Looks like adding:

@AfterClass
public static void afterClass(){
pmf.close();
}

solves the issue.
Any further clarification is appreciated anyway.

Thanks for your patience.
Lorenzo

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: JDO problem : oid is not instanceof javax.jdo.identity.ObjectIdentity

2010-10-14 Thread l.denardo
I managed to reproduce the issue with a simplified model.
Notice that the same code seemed to pass the test yoesterday...not
today.

I can't attach files so I paste the model here


@PersistenceCapable
class Inner{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key key;
}


@PersistenceCapable
class Outer{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key key;

@Persistent
Inner inner;

public Outer(){
inner = new Inner();
}

//  public void setInner(Inner in){
//  inner = in;
//  }
}


@PersistenceCapable
class Container{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key key;

@Persistent
ArrayList outers;

@Persistent
ArrayList inners;

public void addOuters( int n){
outers = new ArrayList();
for (int i = 0; i < n; i++){
outers.add(new Outer());
}
}

public void addInners(int n){
inners = new ArrayList();
for (int i = 0; i < n; i++){
inners.add(new Inner());
}
}
}

public class TestJDOException {

private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new
LocalDatastoreServiceTestConfig());

private static final PersistenceManagerFactory pmf =
JDOHelper.getPersistenceManagerFactory("transactions-optional");

@Before
public void setUp() throws Exception {
helper.setUp();
}

@After
public void tearDown() throws Exception {
helper.tearDown();
}

@Test
public void testAddInners(){
Key key = null;
Container container = new Container();
container.addInners(1);
PersistenceManager pm = pmf.getPersistenceManager();
try{
pm.makePersistent(container);
key = container.key;
}
finally{
pm.close();
}

pm = pmf.getPersistenceManager();
try{
container = pm.getObjectById(Container.class, key);
System.out.println(container.inners);
System.out.println(container.outers);
}
finally{
pm.close();
}
}

@Test
public void testAddOuters(){
Key key = null;
Container container = new Container();
container.addOuters(1);
PersistenceManager pm = pmf.getPersistenceManager();
try{
pm.makePersistent(container);
key = container.key;
}
finally{
pm.close();
}

pm = pmf.getPersistenceManager();
try{
container = pm.getObjectById(Container.class, key);
System.out.println(container.inners);
System.out.println(container.outers);
}
finally{
pm.close();
}
}
}

First test passes, second fails. Every test adding Outers fails as
well.
Thanks to everybody
Lorenzo

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: JDO problem : oid is not instanceof javax.jdo.identity.ObjectIdentity

2010-10-14 Thread l.denardo
I managed to reproduce the issue with a simplified model.
Notice that the same code seemed to pass the test yoesterday...not
today.

I can't attach files so I paste the model here


@PersistenceCapable
class Inner{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key key;
}


@PersistenceCapable
class Outer{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key key;

@Persistent
Inner inner;

public Outer(){
inner = new Inner();
}

//  public void setInner(Inner in){
//  inner = in;
//  }
}


@PersistenceCapable
class Container{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Key key;

@Persistent
ArrayList outers;

@Persistent
ArrayList inners;

public void addOuters( int n){
outers = new ArrayList();
for (int i = 0; i < n; i++){
outers.add(new Outer());
}
}

public void addInners(int n){
inners = new ArrayList();
for (int i = 0; i < n; i++){
inners.add(new Inner());
}
}
}

public class TestJDOException {

private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new
LocalDatastoreServiceTestConfig());

private static final PersistenceManagerFactory pmf =
JDOHelper.getPersistenceManagerFactory("transactions-optional");

@Before
public void setUp() throws Exception {
helper.setUp();
}

@After
public void tearDown() throws Exception {
helper.tearDown();
}

@Test
public void testAddInners(){
Key key = null;
Container container = new Container();
container.addInners(1);
PersistenceManager pm = pmf.getPersistenceManager();
try{
pm.makePersistent(container);
key = container.key;
}
finally{
pm.close();
}

pm = pmf.getPersistenceManager();
try{
container = pm.getObjectById(Container.class, key);
System.out.println(container.inners);
System.out.println(container.outers);
}
finally{
pm.close();
}
}

@Test
public void testAddOuters(){
Key key = null;
Container container = new Container();
container.addOuters(1);
PersistenceManager pm = pmf.getPersistenceManager();
try{
pm.makePersistent(container);
key = container.key;
}
finally{
pm.close();
}

pm = pmf.getPersistenceManager();
try{
container = pm.getObjectById(Container.class, key);
System.out.println(container.inners);
System.out.println(container.outers);
}
finally{
pm.close();
}
}
}

First test passes, second fails. Every test adding Outers fails as
well.
Thanks to everybody
Lorenzo

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: JDO problem : oid is not instanceof javax.jdo.identity.ObjectIdentity

2010-10-14 Thread l.denardo

Looks like the problem is due to a combination of two factors:

*Class Inner has two parents, Outer and Container

AND

*Class Container mantains a list of Inners.

Changing to

@PersistenceCapable
 class Container{
 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 Key key;

 @Persistent
 ArrayList outers;

 @Persistent
 Inner inners;

 public void addOuters( int n){
 outers = new ArrayList();
 for (int i = 0; i < n; i++){
 outers.add(new Outer());
 }
 }

 public void addInners(int n){
 for (int i = 0; i < n; i++){
inner = new Inner();
 }
 }
}

Makes everything work fine.

I have a very similar model which works well in production (it's been
up for nearly one month now).
Hope this helps people facing similar issues. Maybe a short note in
documentation could help.

Regards
Lorenzo

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.