I am trying to look up an object in my envers table, but I dont have the PK. Instead of the PK I have a field ("child") . This is my query,
List resultList = reader.createQuery().forRevisionsOfEntity(TP.class, false, true)
.add(AuditEntity.property("child").eq(nodeid)).getResultList();
But I get this:
Caused by: org.hibernate.PropertyNotFoundException: field [id] not found on java.lang.Long
Or are there any chance of searching by custom fields for revisions?
Regards, Johann
If child is a relation, than you need to use AuditEntity.relatedId("child").eq(nodeid). See also 15.7.1 in the docs
Related
I am unable to get the values from Relationship Attributes using the method getAttributeValue().
I understand this function is the traditional way but are there any alternate methods or workarounds?
getAttributeValue() returs database ID of relationship item.
You can use functions below to work with a relationship attribute:
getEntryRelationshipAttrib
String[] Entry::getEntryRelationshipAttrib(String sAttribPath)
Given a relationship attribute path, returns an array of length 2 containing: [0]=Related Item's Catalog's Name, [1]=Related Item's Primary Key, for the related item. Exception will be thrown if attribute sAttribPath doesn't exist or it's not of relationship type
getItemUsingEntryRelationshipAttrib
Item Entry::getItemUsingEntryRelationshipAttrib(String sAttribPath)
return the related item object for given relationship attribute path. Exception will be thrown if attribute sAttribPath doesn't exist or it's not of relationship type
I'm having an issue that's been blocking me from progressing with an app for a while and I think I'm finally at my wits end of trying to figure it out. For some reason, I can't seem to get foreign keys to work in SQLite.swift/SQLite (I can't figure out whether I'm misusing the library or misunderstanding SQLite in general). I'm trying to use the cascading delete function, and I feel as though I have everything set up correctly, but it isn't working.
Let me make sure my understanding of this is clear first. I have a parent table "Categories" with a child table "Subcategories" that is a parent table to child table "Transactions." Subcategories has a row "category_id" that is related to the "id" row of Categories with a foreign key that cascades on delete. Transactions has a row "subcategory_id" that is related to the "id" row of Subcategories with a foreign key that sets null on delete. When I delete a row from Categories, any row with that category id in Subcategories should also be removed, and any row in Transactions with that subcategory id should have the subcategory id field set to null. Is that correct?
I have all of my SQLite things handled in a single class. Here is a snippet of my code that pertains to the creation of the Subcategories table where I create the foreign keys:
do {
try db!.run(subcategories.create(ifNotExists: true) { table in
table.column(id, primaryKey: .autoincrement)
table.column(name, defaultValue: "New Subcategory")
table.column(sort)
table.column(category_id)
table.column(budget_id)
table.foreignKey(category_id, references: categories, id, update: .cascade, delete: .cascade)
table.foreignKey(budget_id, references: budgets, id, update: .cascade, delete: .cascade)
})
} catch {
print("SQLite: Unable to create 'Subcategories' table")
}
Here is the full code for that class.
If anyone can shed any light on what I'm doing wrong here, I'll give you my firstborn child (or maybe a thanks at least).
I ended up finding the answer here, and it is in fact related to the keys not being enabled.
https://github.com/stephencelis/SQLite.swift/issues/757
Is possible to create a query to update a field that is part of a relationship? I wont update the childs, i just want to update the field into the association....
I tried but I get the error: can not navigate association field
How could I do this?
thank you very much
You do not need a query.
Get the object that represents the relationship, modify the values that you need and then persist it.
I have a dumb question. It would be great if this could be done, but I am not holding my breath.
I need a single column from a table linked to my JPA entity to be a collection in said JPA entity. Is there any way, that I can just get back that column alone that is related to that entity, instead of having to get back an entire table (which could be very costly?)
Can I perform a query inside that JPA entity that will be performed and loaded eagerly into a collection?
I am trying to avoid having to make several calls to the database by just executing a couple of queries.
What are your thoughts on this?
#ElementCollection(fetch=FetchType.EAGER)
#CollectionTable(name="QUICK_LAUNCH_DISTLIST",joinColumns=#JoinColumn(name="QUICK_LAUNCH_ID"))
#Column(name="LIST_ID")
private List<Long> distListIDs;
The ElementCollection attribute is what I was looking for. It seems to work pretty well in addition to that.
Thanks for the help and inspiration guys.
Suppose a Category has many products:
select product.name from Category c inner join c.products product where ...
If that's not what you want, please show an example in your question.
I've got a postgres table where the ID is defined as bigserial. How
can I use #Insert and get back the id of the inserted entity? I am
expecting the mapper method to either return the id or populate the id
field inside the entity object. Any ideas?
The mapper will return you the number of records that were actually inserted.
In order to get back the id of the inserted record, you'll need to add a second annotation (that will populate the id) :
#Options(useGeneratedKeys=true, keyProperty="idSomething")
Note that keyProperty is not necessary if the identifiyng property is named "id" in your entity object.
NVM, i think i found the answer on the other thread,
http://mybatis-user.963551.n3.nabble.com/How-to-return-the-ID-of-the-inserted-object-under-Postgres-td1926959.html
There's the link for anyone else who lands here.