I am thoroughly confused… I am trying to set up a simple one to many
relationship using JPA, I think that this should work but instead I
get the error "Primary key for object of type Member is null." Any
help would be greatly appreciated.
@Entity(name = "Member")
public class Member
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key id;
@Basic //datastore specific type
private Email memberEmail;
private String memberPassword;
private String memberFirstName;
private String memberLastName;
@Basic //blob of text not searchable
private Text memberDescription;
//Member 'owns' the Searches
@OneToMany(mappedBy = "memberWhoCreated", cascade=CascadeType.ALL)
private List < Search > searches = new ArrayList < Search >();
//getters and setters
//...
}
@Entity(name = "Search")
public class Search
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key id;
private List < String > searchStrings;
private boolean allowOthersToSee;
@Basic //datastore specific type
private Text contextOfSearch;
@ManyToOne(fetch = FetchType.LAZY)
private Member memberWhoCreated;
public static Search createASearch(boolean allowOthersToSee, String
context, Member member)
{
Search search = null;
EntityManager em = null;
try
{
//get the entity manager
em = EMF.get().createEntityManager();
//create the search from the form variables
search = new Search();
search.setAllowOthersToSee(allowOthersToSee);
search.setContextOfSearch(new Text(context));
search.setMemberWhoCreated(member);
em.getTransaction().begin();
try
{
//store the member
em.persist(search);
em.getTransaction().commit();
}
finally
{
if (em.getTransaction().isActive())
{
em.getTransaction().rollback();
}
}
}
finally
{
em.close();
}
return search;
}
//getters and setters
//...
}
--
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.