Hey guys, my question is about persisting an entity in JDO. I have created a class, StoredOPDSFeed, whose members persist correctly. However, none of its member objects persist correctly. The class is as follows:
#PersistenceCapable
public class StorableOPDSFeed implements Serializable {
private static final long serialVersionUID = 1L;
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private String primaryKey;
#Persistent
private String locale;
#Persistent
private Date parseDate;
#Persistent
private String title;
#Persistent
private String href;
#Persistent
#Element(dependent = "true")
private ArrayList<OPDSEntry> entries;
#Persistent
#Element(dependent = "true")
private ArrayList<OPDSLink> links = new ArrayList<OPDSLink>();
#Persistent
#Embedded
private SearchDescription searchDescription;
#Persistent
private boolean isStart = false;
#Persistent
#Element(dependent = "true")
private ArrayList<OPDSFacetGroup> facet_groups = new ArrayList<OPDSFacetGroup>();
... and accessors, etc.
}
All of the simple members such as locale, title, href, etc persist correctly. However, all of the complex ones such as searchDescription do not appear in the datastore. There is no reference to them whatsoever, no foreign key, nothing. It's like they are completely ignored. Does anyone have any idea why?
Per request, here is the code for OPDSLink:
#PersistenceCapable
public class OPDSLink implements Serializable {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
#Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String encodedKey;
private static final long serialVersionUID = 1L;
#Persistent
private String href;
#Persistent
private String rel;
#Persistent
private String type;
#Persistent
private String price;
#Persistent
private String currency;
#Persistent
private String dcformat;
#Persistent
private String title;
... and accessors, etc.
}
The GAE JDO documentation states that in one-to-one relationships both involved entities require a key field.
http://code.google.com/appengine/docs/java/datastore/jdo/relationships.html#Owned_One_to_One_Relationships
If the other entity is embedded as intended in your example, the other class (e.g. SearchDescription) requires a #EmbeddedOnly annotation:
http://code.google.com/appengine/docs/java/datastore/jdo/dataclasses.html#Embedded_Classes
In general I found the the following blog interview a good starting point to see what the GAE JDO implementation supports and what not (especially in comparison to third party frameworks such as Objectify and Twig):
http://borglin.net/gwt-project/?page_id=604
Related
I'm trying to isolate some core entities from my project. The idea of this is to share the same users, roles, etc. between many applications.
So, I have this User entity structure from core application, using a database called core:
#Entity
public class MyUser implements UserDetails, Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
#Column(unique = true)
private String username;
private String password;
private String salt;
#ManyToMany(fetch = FetchType.EAGER)
private Set<Role> roles;
private Boolean isAccountNonExpired;
private Boolean isAccountNonLocked;
private Boolean isCredentialsNonExpired;
private Boolean isEnabled;
...
}
On the other hand, I have this other entity from the final application, using a database called myapplication:
#Entity
public class Employee extends MyUser {
private static final long serialVersionUID = 1L;
#Type(type = "date")
private Date birthDate;
#Type(type = "date")
private Date marriageDate;
private Long employeeNum;
private Integer workHs;
#OneToMany
private List<Role> canAssignRoles;
}
I created two datasources and session factories in hibernate.cfg.xml, one for each database, but I cannot achieve the purpose.
How you can see, one entity is mapped to core database, and the other one is mapped to the myapplication database. The Employee entity has a OneToMany mapping to Role.
I have no idea of how to solve this. When Hibernate is creating the database entities, it raises an error when trying to create the entities for myapplication.
I have two tables with relationship as follows, May i know how to exports (csv file), child table with parentid using bulkloader.
Table 1 : Parent
#PersistenceCapable
public class Parent{
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long parentId;
#Persistent
private String name;
#Persistent
private Child child;
Table 2 : Child
public class Child implements StoreCallback {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key childid;
#Persistent
private String name;
A few days ago I've started developing a Backend for Mobile Applications using Google App Engine and Google Cloud Endpoints.
Initially I deployed a first version with the following entity fields:
#Entity
public class Tweet {
#Id
private String id;
private String user;
private String text;
private String date;
private int count;
private String linkTweet;
After a while, I added other fields:
#Entity
public class Tweet {
#Id
private String id;
private String user;
private String text;
private String date;
private int count;
private String linkTweet;
private String imageHttp;
private String imageHttps;
private String userId;
In the datastore I see changes, but when I go to https://myappid.appspot.com/_ah/api/tweetendpoint/v1/tweet I see only the old fields, there aren't the imageHttp imageHttps userId fields :(
Where I'm wrong?
I did the same change and it works fine. The only difference between my code and yours is that I am using JDO and have the tag (#Persistence) before each attribute.
#PersistenceCapable(detachable="true")
public class Test implements Serializable {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private String id;
...
#Persistent
private String newAttribute;
}
NOTE: if you don't have data in new fields, you will not see them in response.
This is an appengine issue. Google guys should fix it soon:
https://code.google.com/p/googleappengine/issues/detail?id=9686
So I am not having any luck with loading the venue and artist object when I load my even object. Basically when I create an event, I load the specific artist and specific venue and save the key in the event's artistKey and venueKey fields. However, when I load even it is always null. I have tried annotations "#Persistent(defaultFetchGroup = "true")" and also "#Persistent(mappedBy = "venue") #Element(dependent = "true")" on my venue and artist with no luck as artist/venue still come up as null when I load an event (the keys are there). When I try the defaultFetchGroup it says I cannot load a parent if it has already been persisted, which make sense I guess.
public class Event {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
#Persistent
private Key artistKey;
#Persistent
private Key venueKey;
private Artist artist;
private Venue venue;
//other fields
//getters and setters
}
#PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Venue {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
//other fields
//getters and setters
}
#PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Artist {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
//other fields
//getters and setters
}
with relations (in GAE) you have to pay attention to whether they are owned (stored with the owning object in the datastore) or unowned (like they are in all other datastores). You can mark relations as #Unowned if the latter. GAE has some restrictions around entity groups that impact on this - see their docs
I'm starting my first app with Google Appengine and I am using JDO for managing persistence. I come from a relational database background so I'm having a bit of difficulty getting my head around the appengine datastore and the restrictions it has when it comes to joins.
In my simple example I have a Car and Owner object. Each car has one owner. I'd like to be able to select a car based on the id of the owner (simple to do in regular sql). Is this possible on appengine and if so, how would I go about do it?
Thanks
B
Below are my objects.
#PersistenceCapable
public class Car {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
#Persistent
private String name;
#Persistent
private String colour;
#Persistent(defaultFetchGroup = "true", dependent = "true")
private Owner owner;
…
…
}
#PersistenceCapable
public class Owner {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
#Persistent
private String name;
…
…
}