Spring Jpa- Instead of updating a row, I'm accidentally adding a new one - spring

Spring Jpa- Instead of updating a row, I'm accidentally adding a new one with different id(primary key). I'm using .save() to update a row, but instead of updating its adding new row in the table..
Here, instead of "where task_user_id" I need task_tId, which is the primary key.. How do I do that??
Log : select task0_.t_id as t_id1_0_, task0_.creation_date as creation2_0_, task0_.status as status3_0_, task0_.target_date as target_d4_0_, task0_.task_desc as task_des5_0_, task0_.user_id as user_id6_0_ from tasks task0_ where task0_.user_id=? limit ?

Related

Increment column value automatically in every update

I have created Entity having field as updateCount (non id column),
While first save.. I provide value = 1 for this column. But for every time if I update this entity , I want this column should auto increment.
Is there any way in Spring Jpa/Hibernate to do so? This will help to get latest update count for that record in case of concurrent update.
use #Version int version in your model; spring does it for you automaitcally in every update

AWS Glue - disabling bookmarks for some of sources in the job

I've got a data warehouse with star pattern - fact table and multiple dimensions around that. They are connected by foreign keys.
I've got two AWS Glue jobs:
Populates dimensions (run on-demand, they doesn't change often)
Populates fact table (should be run even every hour to get fresh fact data in warehouse)
So the situation is: I've got filled-in dimension tables using first job. In second job I need to get only fresh data for fact table, find foreign keys for each record in dimension table and persist new row in fact table.
Problem is, that when using bookmarks, AWS Glue thinks that since dimension tables didn't change since last run, nothing is there and inserts null as foreign keys.
I tried to disable bookmarking by removing transformation_ctx from the generated script, but it didn't work.
From this:
dimension_node1647201451763 = glueContext.create_dynamic_frame.from_catalog(
database="foobar-staging",
table_name="dimension",
transformation_ctx="dimension_node1647201451763",
)
I did that:
foobaritem_node1647201451763 = glueContext.create_dynamic_frame.from_catalog(
database="foobar-staging",
table_name="foobar_item",
)
But still those record were not found.
Only solution that I can imagine is disabling bookmarks completely and then add "not exists" checks for all records processed, which would prevent duplicates.

postgresql custom primarykey

I try to make a project using hibernate and postgres as DB. The problem I have is I need to store the primary key as this 22/2017 or like 432/1990.
Let's say the first number is object_id and second year_added.
I think what I want to achieve is to make a first number and second number together a primary key so 22/2017 is different from 22/2016.
The only idea I have is when user add new object I generate current date year and trying to find last id and increment it.
So next year first added object should be : 1/2018.
So far in my db only object_id is stored as a primary key.
This solution seems to work fine:
PostgreSQL: Auto-increment based on multi-column unique constraint
Thanks for helping me anyway.

HBase row key design for reads and updates

I'm try to understand the best way to design the key for my HBase Table.
My use case :
Structure right now
PersonID | BatchDate | PersonJSON
When some thing about the person is modified, a new PersonJSON and new a batchdate is inserted in to Hbase updating the old records. And every 4 hours a scan of all the people who are modified are then pushed to Hadoop for further processing.
If my key is just personID it great for updating the data. But my performance sucks because I have to add a filter on BatchData column to scan all the rows greater than a batch date.
If my key is a composite key like BatchDate|PersonID I could use startrow and endrow on the row key and get all the rows that have been modified. But then I would have lot of duplicated since the key is not unique and can no longer update a person.
Is bloom filter on row+col (personid+batchdate) an option ?
Any help is appreciated.
Thanks,
Abhishek
In addition to the table with PersonID as the rowkey, it sounds like you need a dual-write secondary index, with BatchDate as the rowkey.
Another option would be Apache Phoenix, which provides support for secondary indexes.
I usually do two steps:
Create table one just have key is commbine of BatchDate+PersonId, value could be empty.
Create table two just as normal you did. Key is PersonId Value is the whole data.
For date range query: query table one first to get the PersonIds, and then use Hbase batch get API to get the data by batch. it would be very fast.

Full copy of datatable's row

I need to copy a row in a datatable with it's child row. Do I have to iterate every child table or is there a faster way to do this?
Thanks in advance.
EDIT: i make an example:
-row of DataTable "ParentTable" (with primary key "keyField")
-row DataTable "ChildTable" (with foreign key "keyField")
I need a copy of this block, i need to change the primary key (and so the foreign key by constraints), then delete the original row, but doing this, i loose also the row of "ChildTable"
You could use JOIN,LEFT JOIN, RIGHT JOIN to get all the results you want in one fell swoop.
You can get get it from the query result which you use to build the datatable or using fnGetData.
$('#yourTable').dataTable().fnGetData(rowNumber);
You can see the reference for more datails.

Resources