vaninh0, you can only create owned relationships in the datastore if the child's key is of type com.google.appengine.api.datastore.Key or String ("Key as Encoded String").
Check this part of the documentation: http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys Cheers, jpt On Nov 18, 12:15 pm, vaninh0 <vani...@gmail.com> wrote: > Ops, I posted with one mistake... correcting: > > �...@entity(name = "Usuario") > �...@table(name = "usuario") > public class Usuario { > �...@id > �...@column(name = "id_usuario") > �...@generatedvalue(strategy = GenerationType.IDENTITY) > private Long id; > �...@manytoone(fetch = FetchType.LAZY) > �...@joincolumn(name = "id_empresa") > private Empresa empresa; > > } > > On 18 nov, 08:13, vaninh0 <vani...@gmail.com> wrote: > > > > > > > > > I have these Entities: > > > @Entity(name = "Empresa") > > @Table(name = "empresa") > > public class Empresa { > > @Id > > @Column(name = "id_empresa") > > @GeneratedValue(strategy = GenerationType.IDENTITY) > > private Long id; > > > } > > > and > > > @Entity(name = "Usuario") > > @Table(name = "usuario") > > public class Usuario { > > @Id > > @Column(name = "id_usuario") > > @GeneratedValue(strategy = GenerationType.IDENTITY) > > private Long id; > > @ManyToOne(fetch = FetchType.LAZY) > > @JoinColumn(name = "id_empresa") > > > } > > > I have inserted many of Empresas and now I wanna insert a new Usuario > > with a inserted Empresa, but I got this exception: > > > javax.persistence.PersistenceException: Error in meta-data for > > br.com.controlecartao.core.entity.Empresa.id: Cannot have a > > java.lang.Long primary key and be a child object (owning field is > > br.com.controlecartao.core.entity.Usuario.empresa). > > > I´m using the method MERGE, but I don´t know if this method is correct > > to to this. > > > What´s the correct way to do this? > > Where am I wrong? > > > Thank you. -- 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.