[appengine-java] Error removing Entity

2012-02-21 Thread Fernando Jorge Santos
Hi all,

I'm facing some problems trying to remove an entity from the database.
I have an interface to abstract the AppEngine Entity from my business
Object. I can easily Insert and Update, but when I try to delete I got
the error:

java.lang.UnsupportedOperationException: Non-owned relationships are
not currently supported
at
org.datanucleus.store.appengine.DatastoreFKListStoreSpecialization.clearWithoutDelete(DatastoreFKListStoreSpecialization.java:
123)
at org.datanucleus.sco.backed.List.clear(List.java:817)
at
org.datanucleus.store.mapped.mapping.CollectionMapping.preDelete(CollectionMapping.java:
299)
at
org.datanucleus.store.appengine.DependentDeleteRequest.execute(DependentDeleteRequest.java:
71)
...

I got the interface :

public interface ICompany extends IEntityBean {
  // Getters
  public List getUsers();

  public List getDepartments();

  public ICurrency getCurrency() throws Exception;
}

And I got the implementation

public class GAECompany extends GAEEntityBean implements ICompany {

  @Override
  @OneToMany(mappedBy = "company")
  public List getUsers() {
return this.users;
  }

  @Override
  @OneToMany(mappedBy = "company")
  public List getDepartments() {
 return this.departments;
  }

  @Transient
  public ICurrency getCurrency() throws Exception {
return this.currency;
  }
}

The code I'm using to remove:

  // Get the entity manager
  EntityManager em = this.getDBManager();
  // Find the object
  IEntityBean persistent = em.find(obj.getClass(), obj.getId());

  // Remove it
  em.remove(persistent);
  em.flush();

I don't have any dependent objects I've just created an Company and
I'm trying to delete it
I assumed the mapping is right cause I'm able to INSERT an UPDATE the
company. but not REMOVE!
Am I doing something wrong??

Tks guys!

-- 
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-java@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: Can't see new objects in the same transaction

2012-02-02 Thread Fernando Jorge Santos
Wow man!!

That works fine!! Thanks a lot...


On Feb 2, 10:42 am, Nichole  wrote:
> You'll want to use flush() instead of refresh().  flush() saves your
> current state to the datastore
> and because they are not detached, the entities within your
> transaction will already be
> in sync.  If you use refresh(), you are tossing any changes you made
> to your entities
> and fetching the last state from the datastore.
>
> On Feb 1, 2:22 am, Fernando Jorge Santos  wrote:
>
>
>
>
>
>
>
> > Hi all,
>
> > I'm new in JPA / JDO and I'm totally sure I'm doing something wrong. I
> > don't know why I can't see children objects in the same transactions using
> > the same PM
>
> > 
>
> > // Here I got the DatastoreEntityManager (id=92)
> > DAO dao = DAO.getInstance(DAO.JPA, requestor);
>
> > // Here I got the DatastoreEntityTransactionImpl (id=94)
> > dao.startTransaction()
>
> > // Then I create and maker persistent a new Department (id=114)
> > // It uses the same DatastoreEntityManager (id=92) and
> > DatastoreEntityTransactionImpl (id=94)
> > Department department = new Department()
> > department.setName("New department");
> > dao.persist(department);
> > dao.refresh(department);
>
> > // Then I create and make persistent a new Account (id=224)
> > Account account = new Account();
> > account.setNumber(12345);
> > account.setDepartment(department); // Owned relationship working fine
> > dao.persist(account);
> > dao.refresh(account);
>
> > // Now I'm testing it
> > department.getId() // returns Department(22)
> > account.getId() // returns Department(22)/Account(24)
> > department.getAccounts(); // Returns an empty list
> > __
>
> > At some point down the line I gotta get the accounts in the same
> > transaction to use in another entity. I've tried to add manually the new
> > Account to the* Department.accounts* field but when I tried to do it I get
> > *javax.jdo.JDODetachedFieldAccessException:* You have just attempted to
> > access property "accounts" yet this property was not detached when you
> > detached the object. Either dont access this property, or detach it when
> > detaching the object.
>
> > Does someone faced the same?? I'm loosing my hair with this!!
>
> > Thanks guys!

-- 
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-java@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] Can't see new objects in the same transaction

2012-02-01 Thread Fernando Jorge Santos
Hi all,

I'm new in JPA / JDO and I'm totally sure I'm doing something wrong. I 
don't know why I can't see children objects in the same transactions using 
the same PM



// Here I got the DatastoreEntityManager (id=92)
DAO dao = DAO.getInstance(DAO.JPA, requestor); 

// Here I got the DatastoreEntityTransactionImpl (id=94)
dao.startTransaction()

// Then I create and maker persistent a new Department (id=114)
// It uses the same DatastoreEntityManager (id=92) and 
DatastoreEntityTransactionImpl (id=94)
Department department = new Department()
department.setName("New department");
dao.persist(department);
dao.refresh(department);

// Then I create and make persistent a new Account (id=224)
Account account = new Account();
account.setNumber(12345);
account.setDepartment(department); // Owned relationship working fine
dao.persist(account);
dao.refresh(account);

// Now I'm testing it
department.getId() // returns Department(22)
account.getId() // returns Department(22)/Account(24)
department.getAccounts(); // Returns an empty list
__

At some point down the line I gotta get the accounts in the same 
transaction to use in another entity. I've tried to add manually the new 
Account to the* Department.accounts* field but when I tried to do it I get
*javax.jdo.JDODetachedFieldAccessException:* You have just attempted to 
access property "accounts" yet this property was not detached when you 
detached the object. Either dont access this property, or detach it when 
detaching the object.

Does someone faced the same?? I'm loosing my hair with this!!

Thanks guys!

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/ukeIAZZOS0MJ.
To post to this group, send email to google-appengine-java@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.