Re: [appengine-java] Re: Persistence with JPA + GAE

2010-02-09 Thread Johan Vallejo




Hi Jake, 
Now i have this error

Log :

javax.persistence.PersistenceException: Transaction is still active. You should always close your transactions correctly using commit() or rollback().

this is my code :

   EntityManager cn2 =
emf.get().createEntityManager(); 
 distritos dist2 = cn2.find(distritos.class, id);
 evento e = new evento();
 e.setDistrito(dist2);
 Date fecha = new Date();
 e.setFechaCreacion(fecha);
 try{ 
 cn2.getTransaction().begin(); 
 cn2.persist(e);
 cn2.getTransaction().commit();
 response.getWriter().write("ok"); 
 }finally{
 cn2.close();
 }

Distrito :
@Entity
public class distritos implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Extension (vendorName="datanucleus", key="gae.encoded-pk",
value="true")
 Key id;

 --getter and setter--


El 08/02/2010 03:37 p.m., Jake escribi:

  Hello,

The Google Datastore has four ways that you can store a Primary Key
ID:  String, Long, and two variations on Google's own Key object.  If
you want to create a parent/child relationship between two persisted
objects (in your case, evento is the parent and distritos is the
child), then you need to use Google's Key object as the primary ID.
See:  http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys
"If the class is used as a "child" class in a relationship, the key
field must be of a type capable of representing an entity group
parent: either a Key instance, or a Key value encoded as a string."
So, you have two options:

1.  Change your Long id values to Key id values.
2.  Instead of storing "private distritos distrito" directly in your
evento object, store a reference to the id: "private Long distrito_id"

Jake

On Feb 6, 4:06pm, chevelle jvall...@vnperu.com wrote:
  
  
Hi
I am new in the list, in these days i am trying save data between two
entity beans using JPA but without success, i am cheking the log nd
says:

Uncaught exception from servlet
javax.persistence.PersistenceException: Error in meta-data for
beans.distritos.id: Cannot have a java.lang.Long primary key and be a
child object (owning field is beans.evento.distrito).

this is my servlet:
  Long id =
Long.parseLong(request.getParameter("idDistrito"));
  response.setContentType("text/html");
  EntityManager cn = emf.get().createEntityManager();

  Query q = cn.createQuery("SELECT d FROM distritos d WHERE
d.id = :codigo");
  q.setParameter("codigo",id);
  distritos dist = (distritos) q.getSingleResult();

  EntityManager cn2 = emf.get().createEntityManager();
  cn2.getTransaction().begin();

  evento e = new evento();
  e.setDistrito(dist);
  Date fecha = new Date();
  e.setFechaCreacion(fecha);

  try{
cn2.persist(e);
response.getWriter().write("ok");
  }finally{
cn2.getTransaction().commit();
cn2.close();
  }

this is my entity bean

Evento:
@Entity
public class evento implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  Long id;

  @Temporal(javax.persistence.TemporalType.DATE)
  private Date fechaCreacion;

  @JoinColumn
  @OneToMany(cascade = CascadeType.ALL)
  private distritos distrito;

 --getter and setter--

Distrito:
@Entity
public class distritos implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  Long id;
  private String distrito;

  --getter and setter--

i hope anyone help me, Thank!

Johan

  
  
  







-- 
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.




Re: [appengine-java] Re: Persistence with JPA + GAE

2010-02-09 Thread Johan Vallejo




Hi Diego
Yes, i try using Long and Key but with both i have the error

Log :

javax.persistence.PersistenceException: Transaction is still active. You should always close your transactions correctly using commit() or rollback().



El 09/02/2010 01:06 p.m., Diego Osse Fernandes escribi:
Hi Johan,
  
  
  you can use the Long as PK
  
  
  
@Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 Long id;
  
  
  
  
  []'s
  Diego
  
  2010/2/9 Johan Vallejo jvall...@vnperu.com
  
Hi Jake, 
Now i have this error

Log :

javax.persistence.PersistenceException: Transaction is still active. You should always close your transactions correctly using commit() or rollback().

this is my code :

   EntityManager cn2 =
emf.get().createEntityManager(); 
 distritos dist2 = cn2.find(distritos.class, id);
 evento e = new evento();
 e.setDistrito(dist2);
 Date fecha = new Date();
 e.setFechaCreacion(fecha);
 try{ 
 cn2.getTransaction().begin(); 
 cn2.persist(e);
 cn2.getTransaction().commit();
 response.getWriter().write("ok"); 
 }finally{
 cn2.close();
 }

Distrito :
@Entity
public class distritos implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Extension (vendorName="datanucleus", key="gae.encoded-pk",
value="true")
 Key id;

 --getter and setter--


El 08/02/2010 03:37 p.m., Jake escribi:

  Hello,

The Google Datastore has four ways that you can store a Primary Key
ID:  String, Long, and two variations on Google's own Key object.  If
you want to create a parent/child relationship between two persisted
objects (in your case, evento is the parent and distritos is the
child), then you need to use Google's Key object as the primary ID.
See:  http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys
"If the class is used as a "child" class in a relationship, the key
field must be of a type capable of representing an entity group
parent: either a Key instance, or a Key value encoded as a string."
So, you have two options:

1.  Change your Long id values to Key id values.
2.  Instead of storing "private distritos distrito" directly in your
evento object, store a reference to the id: "private Long distrito_id"

Jake

On Feb 6, 4:06pm, chevelle jvall...@vnperu.com wrote:
  
  
Hi
I am new in the list, in these days i am trying save data between two
entity beans using JPA but without success, i am cheking the log nd
says:

Uncaught exception from servlet
javax.persistence.PersistenceException: Error in meta-data for
beans.distritos.id: Cannot have a java.lang.Long primary key and be a
child object (owning field is beans.evento.distrito).

this is my servlet:
  Long id =
Long.parseLong(request.getParameter("idDistrito"));
  response.setContentType("text/html");
  EntityManager cn = emf.get().createEntityManager();

  Query q = cn.createQuery("SELECT d FROM distritos d WHERE
d.id = :codigo");
  q.setParameter("codigo",id);
  distritos dist = (distritos) q.getSingleResult();

  EntityManager cn2 = emf.get().createEntityManager();
  cn2.getTransaction().begin();

  evento e = new evento();
  e.setDistrito(dist);
  Date fecha = new Date();
  e.setFechaCreacion(fecha);

  try{
cn2.persist(e);
response.getWriter().write("ok");
  }finally{
cn2.getTransaction().commit();
cn2.close();
  }

this is my entity bean

Evento:
@Entity
public class evento implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  Long id;

  @Temporal(javax.persistence.TemporalType.DATE)
  private Date fechaCreacion;

  @JoinColumn
  @OneToMany(cascade = CascadeType.ALL)
  private distritos distrito;

 --getter and setter--

Distrito:
@Entity
public class distritos implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  Long id;
  private String distrito;

  --getter and setter--

i hope anyone help me, Thank!

Johan

  




-- 
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.
  
  
  
  
-- 
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] persistence with JPA

2010-02-08 Thread Johan Vallejo




Hi
I am new in the list, in these days i am trying save data between two
entity beans using JPA but without success, i am cheking the log nd
says:

Uncaught exception from servlet
javax.persistence.PersistenceException: Error in meta-data for beans.distritos.id: Cannot have a java.lang.Long primary key and be a child object (owning field is beans.evento.distrito).


this is my servlet:
 Long id =
Long.parseLong(request.getParameter("idDistrito"));
 response.setContentType("text/html");
 EntityManager cn = emf.get().createEntityManager();

 Query q = cn.createQuery("SELECT d FROM distritos d WHERE
d.id = :codigo");
 q.setParameter("codigo",id);
 distritos dist = (distritos) q.getSingleResult();

 EntityManager cn2 = emf.get().createEntityManager();
   cn2.getTransaction().begin();

 evento e = new evento(); 
 e.setDistrito(dist);
 Date fecha = new Date();
 e.setFechaCreacion(fecha);

 try{
 cn2.persist(e);
 response.getWriter().write("ok");
 }finally{
 cn2.getTransaction().commit();
 cn2.close();
 }


this is my entity bean

Evento:
@Entity
public class evento implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 Long id;

 @Temporal(javax.persistence.TemporalType.DATE)
 private Date fechaCreacion;

 @JoinColumn
 @OneToMany(cascade = CascadeType.ALL)
 private distritos distrito;

 --getter and setter--



Distrito:
@Entity
public class distritos implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 Long id;
 private String distrito;
 
 --getter and setter--


i hope anyone help me, Thank!





-- 
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] Persistence in JPA

2010-02-08 Thread Johan Vallejo




Hi
I am new in the list, in these days i am trying save data between two
entity beans using JPA but without success, i am cheking the log nd
says:


Uncaught exception from servlet
javax.persistence.PersistenceException: Error in meta-data for beans.distritos.id: Cannot have a java.lang.Long primary key and be a child object (owning field is beans.evento.distrito).


this is my servlet:
 Long id =
Long.parseLong(request.getParameter("idDistrito"));
 response.setContentType("text/html");
 EntityManager cn = emf.get().createEntityManager();

 Query q = cn.createQuery("SELECT d FROM distritos d WHERE
d.id = :codigo");
 q.setParameter("codigo",id);
 distritos dist = (distritos) q.getSingleResult();

 EntityManager cn2 = emf.get().createEntityManager();
   cn2.getTransaction().begin();

 evento e = new evento(); 
 e.setDistrito(dist);
 Date fecha = new Date();
 e.setFechaCreacion(fecha);

 try{
 cn2.persist(e);
 response.getWriter().write("ok");
 }finally{
 cn2.getTransaction().commit();
 cn2.close();
 }


this is my entity bean

Evento:
@Entity
public class evento implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 Long id;

 @Temporal(javax.persistence.TemporalType.DATE)
 private Date fechaCreacion;

 @JoinColumn
 @OneToMany(cascade = CascadeType.ALL)
 private distritos distrito;

 --getter and setter--



Distrito:
@Entity
public class distritos implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 Long id;
 private String distrito;
 
 --getter and setter--


i hope anyone help me, Thank!
 

-- 
Atentamente,
Johan Vallejo Elias
Soluflex ERP
Nextel  : 827*239
Celular : 998270239
Oficina : 434-2649 anexo 102
Skype : soporte_soluflex
Web : www.guiadecalles.pe
Blog 1 : www.vnperu.com/blog
Blog 2 : www.rfid.com.pe








-- 
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.




Re: [appengine-java] DELETE HTTP Method not working on Google Chrome

2010-02-08 Thread Johan Vallejo

Francisco send your code for help you

El 08/02/2010 10:55 a.m., Francisco Gonzalez escribió:

Hi.

I'm developing an application that receives AJAX requests to perform 
some actions. I'm using jQuery to send the requests from the client.


One of those requests is of type HTTP DELETE.

The problem is that this request does not work when using Google 
Chrome on the deployed app. It gets a 400 error (bad request) as 
response.


It works fine on my local SDK though. Firefox works well on both SDK 
and the deployed app.


Anyone having the same trouble? Any ideas?

Thank you in advance!
--
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.


--
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.



Re: [appengine-java] Re: Persistence with JPA + GAE

2010-02-08 Thread Johan Vallejo

hi jake, thank for you answer
i will try you suggestion and i will tell later

El 08/02/2010 03:37 p.m., Jake escribió:

Hello,

The Google Datastore has four ways that you can store a Primary Key
ID:  String, Long, and two variations on Google's own Key object.  If
you want to create a parent/child relationship between two persisted
objects (in your case, evento is the parent and distritos is the
child), then you need to use Google's Key object as the primary ID.
See:  
http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys
If the class is used as a child class in a relationship, the key
field must be of a type capable of representing an entity group
parent: either a Key instance, or a Key value encoded as a string.
So, you have two options:

1.  Change your Long id values to Key id values.
2.  Instead of storing private distritos distrito directly in your
evento object, store a reference to the id: private Long distrito_id

Jake

On Feb 6, 4:06 pm, chevellejvall...@vnperu.com  wrote:
   

Hi
I am new in the list, in these days i am trying save data between two
entity beans using JPA but without success, i am cheking the log nd
says:

Uncaught exception from servlet
javax.persistence.PersistenceException: Error in meta-data for
beans.distritos.id: Cannot have a java.lang.Long primary key and be a
child object (owning field is beans.evento.distrito).

this is my servlet:
 Long id =
Long.parseLong(request.getParameter(idDistrito));
 response.setContentType(text/html);
 EntityManager cn = emf.get().createEntityManager();

 Query q = cn.createQuery(SELECT d FROM distritos d WHERE
d.id = :codigo);
 q.setParameter(codigo,id);
 distritos dist = (distritos) q.getSingleResult();

 EntityManager cn2 = emf.get().createEntityManager();
 cn2.getTransaction().begin();

 evento e = new evento();
 e.setDistrito(dist);
 Date fecha = new Date();
 e.setFechaCreacion(fecha);

 try{
 cn2.persist(e);
 response.getWriter().write(ok);
 }finally{
 cn2.getTransaction().commit();
 cn2.close();
 }

this is my entity bean

Evento:
@Entity
public class evento implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 Long id;

 @Temporal(javax.persistence.TemporalType.DATE)
 private Date fechaCreacion;

 @JoinColumn
 @OneToMany(cascade = CascadeType.ALL)
 private distritos distrito;

--getter and setter--

Distrito:
@Entity
public class distritos implements Serializable {
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 Long id;
 private String distrito;

 --getter and setter--

i hope anyone help me, Thank!

Johan
 
   


--
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.