> the problem is simple:
>
> @Entity
> public class Company implements Serializable {
>     // ...
>     public Company(String irsEIN) {
>         ein = irsEIN;
>         // ...
>     }
>
>     @Id String ein; // the IRS EIN for the company ... this is a
> unique id and a good one to use for PK?
>
>    // ...
>
> }
>
> ... no it isn't because you get an exception when you commit one of
> these suckers:
>
> WARNING: java.lang.IllegalArgumentException: Name may not start with a
> digit.

http://code.google.com/p/googleappengine/issues/detail?id=1352

>
> So, you think, "no problem I actually want it as a number anyway..."
> so you change the code like so:
>
> @Entity
> public class Company implements Serializable {
>     // ...
>     public Company(Long irsEIN) {
>         ein = irsEIN;
>         // ...
>     }
>
>     @Id Long ein; // the IRS EIN for the company ... this is a unique
> id and a good one to use for PK?
>
>    // ...
>
> }
>
> Problem solved? ....
>
> WARNING: javax.persistence.PersistenceException: Attempt was made to
> manually set the id component of a Key primary key.  If you want to
> control the value of the primary key, set the name component instead.

It looks that 'Long' id is always generated automatically, you cannot
set it manually.

http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys
------------
Long

    A long integer (java.lang.Long), an entity ID automatically
generated by the datastore.
---------

I suggest to read the link above carefully, it could save a lot of
your time.

>         at
> org.datanucleus.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException
> (NucleusJPAHelper.java:264)
>         at org.datanucleus.jpa.EntityTransactionImpl.commit
> (EntityTransactionImpl.java:122)
>
> Nope! ...
>
> Now I want to use JPA because I want my code to be portable, so I
> really dont want to care about JDO,
> DataNucleus or the App Engine Datastore ...

@Entity and @Id is a part of JPA (not JDO).

>
> This exception error message is meaningless to me ... even after
> reading the App Engine and DataNucleus
> documentation ...
>
> Also, on a slightly related issue, should I have to obtain an
> EntityManager transaction for each instance
> of this class I wish to persist?
>
> I'd appreciate any suggestions anyone might have?

No need to get EntityManager for each class. It is a good practice to
have one EntityManager instance for each request. But it is up to 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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to