I have a ClassA containing an ArrayList of another ClassB
I can save a new instance of ClassA with ClassB instances also saved using JDO.
However,
When I retrieve the instance of Class A,
I try to do like the below:
ClassA instance = PMF.get().getPersistenceManager().GetObjectByID( someid );
instance.GetClassBArrayList().add( new ClassB(...) );
I get an Exception like the below:
Uncaught exception from servlet com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found..
So I was wondering, Is it possible to add a new item to the previously saved collection?
Or was it something I missed out.
Best Regards
"no matching index found"
Perhaps you need to add some index in GAE/J's datastore ?
Nothing to do with JDO
Related
I did a refactoring and now my class B is not an Entity anymore but a Value.
If I try viewing the diff of an already audited Entity A, that contains a list of B's I am getting this exception: JaversException MANAGED_CLASS_MAPPING_ERROR: given javaClass 'class B' is mapped to ValueType, expected EntityType
Is there a recommended way how to fix this?
Sadly, looks like there is no workaround other than manually deleting snapshots of previous Entity.
I have created the issue for this case https://github.com/javers/javers/issues/753
I have several classes, all of which have an ID field declared as Integer the next way:
#Expose
#DatabaseField(columnName = "_id", id = true)
private Integer idField;
Everything compiles and runs correctly, but when I simply try to check if a record exists:
Integer idField = 1;
result = DBHelper.getHelper().getClassDAO().idExists(idField);
I get the exception:
java.sql.SQLException: Field '_id' is of data type null which can not be compared
The thing is that with one class (let's name it A) the method works properly, but with the others fail and I don't know which is the cause because all the classes have its ID field declared the same way.
I'm getting this exception too if I try to createOrUpdate the object of any class, except the refered class A.
Any helping hand would be appreciated.
NOTE. The project uses an ormlite_config.txt file, which is updated.
After a few hours debugging I came into that the mentioned exception comes only when the class to be saved has one o more collections. As far as I know, the exception is thrown inside the idExists method of the Dao class. Having in mind that the createOrSave method surely must call it, that's why I get the SQLException in both cases.
And now, the workaround to solve this. Rather than invoking the idExists method, I had to create my own like this:
return DBHelper.getHelper().getMyDAO().queryForId(idField) != null;
And instead of calling the createOrUpdate method, first I check if the record exists and then, depending on the result, I call the create or update method of the Dao class I want to persist.
I'm a newbie in Hibernate and would like to abstract the load() method of hibernate session so that i can use it to load any arbitrary object from a database. I'm creating a utility class to persist and find objects in a database because am working with multiple classes.
Since the the load() method accepts a class name followed by the class keyword i am struggling how to do it. i did the following but is giving me errors ::
Object ob = session.load(Object.class, id);
How do i get it right?
thanks
There is no way to do a request without specifying of a class name because of Hibernate need a mapping information from a class to make SQL requests.
You can use HQL. Something like this (maybe, you can use a query parameter for id to better caching)
public static <T> getById(String persistentClassName, Long id) {
return (T) session.createQuery(String.format("from %s where id=%d",
persistentClassName, id).uniqueResult();
}
Persitent p = getById("Persistent", 100L);
But as #sᴜʀᴇsʜᴀᴛᴛᴀ suggested it is not a very good design. if you want to have ideas for more convenient approach to design such utilities methods you can take a look at fluent-hibernate. With it you can do such kind of requests
List<Transaction> transactions = H.<Transaction> request(Transaction.class)
.innerJoin("customer").innerJoin("merchant").proj("customer.name")
.proj("merchant.name").proj("amountDue").transform(Transaction.class).list();
I'd like to store my Android application's data in a Parse.com database, but I'm having trouble right now. I'm trying to save my own 'Parent' class. The Parent class has different attributes. Right now I'd like to store these:
private String email;
private String password;
There are more attributes, but atm I'm not filling em up during runtime, will do so later when I know the whole idea works.
I am aware of the classes ParseUser and ParseObject, a user and an object class of Parse, which can be used to store data to their DB. Now my first approach was to let my own Parent class inherit from Parse's ParseUser or ParseObject. That way my class would have access to the Parse's methods, while maintaining my own attributes and methods. I tried that and I don't think it works. It gave a vague error, with no clear error message. (click on the next link for a pic http://i.imgur.com/orkmjXO.png )
Right now my Userr class inherits from ParseObject. Well not directly, but it has access to ParseObejct's methods. the hierarchy goes like this ParseObject -> (mine) User -> (mine) Parent. Below I pasted the code I use at the point of saving.
Parent user = new Parent();
user.setEmail(mEmail);
user.setWachtwoord(mPassword);
user.put(mEmail, user);
user.saveInBackground();
Could anyone help me and tell me how I can store my own classes in Parse? Any kind of help would be appreciated, like possible causes and such. Thanks!
as per the parse docs, looks like ParseObject is like a Map.
refer: https://www.parse.com/apps/quickstart#parse_data/mobile/android/native/new
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", "bar");
testObject.saveInBackground();
so I guess, in you case this would translate to:
user.put("mEmail", "user1");
user.saveInBackground();
Using seam-gen based code. I have an object "Classroom", which contains an instance of "Location". I want to query for classrooms but specifying a value on the Location object.
Something like 'select from Classroom where Location.State = "NY"'. When I try to bind a selectOneMenu with a list of states to #{ClassroomList.classroom.location.state} I'm getting errors.
Was getting a null pointer exception on Location. I'm assuming I need to instantiate a new "Location" on the Classroom object, but not sure where to do that. On the Classroom entity's constructor? On the ClassroomList backing bean (where the example object is bound to the ClassroomList JSP search fields)?
Yes, you need to instantiate ClassroomList.instance.Location. Because the ClassroomList.instance is not bound to the Database, this is not done automagically
Not sure if this is the best way, but I got it working.
I have a String exposed on my ClassroomList backing bean as "String locationState". My dropdown list of states binds to that
Then that's referenced in my restrictions as:
...
lower(classroom.location.state) like lower(concat(#{classroomList.locationState}, '%'))",
...
--
When I tried to instantiate ClassroomList.instance.Location, I would get:
javax.servlet.ServletException with message: "Id and clazz must not be null"
Not sure what's causing that?