I have 2 types of transaction :
orderrequest ( provide details including orderer name and transaction id )
ordereraccept (provide id of the orderrequest transaction being accepted)
within the transaction processor function of orderaccept i want to refer to the previous orderrequest transaction using the id to perform validation
i was thinking of using some form of historian but have not been able to get anything to work .
In the test section of composer playground i am able to view previous transactions so I just need a way to do this within a transaction processor function
Thanks a lot
Related
I am doing mass save with JpaRepository.I used #Transactional but it didn't work.I summarize the process I did:
I have two Enties
THeaderEntity
TDetailsEntity
First of all, I save the TheaderEntity because the THeaderEntity's information will be used in the TDetailsEntity (One To Many, CrudRepository.save(), 1 Header for 50 Details)
Then turn and save in the TDetailsEntity's loop.I want the entire process rollback if any registry gets an error.
#Transactional
public Result createTdetailsFromHeaderId(String token, String headerId, DetailRequests detailRequests)
I used #Transactional but only the record that received the error was rollback.
To answer why only 1 record is rolled back you might look into Spring's transactional logic - I suspect from your description that 1 transaction is opened for every save but an easy way to work on this is:
Adjust the #OneToMany relationship to cascade the persisting of entities.
Create the appropriate entities (1 THeaderEntity and 50 TDetailsEntity having all object references set correctly).
save the THeaderEntity that then should cascade the persisting to its TDetailsEntity.
Context :-
I'm validating my rest apis in spring boot. There's a transaction id that is being sent in every API call. I'm writing a custom annotation to ensure that the transaction id that is sent every time is unique. Here's an example of the request api body :-
{
"timestamp": "2020-05-12T04:15:28.318Z",
"txnid": "acscscs-4a18-11e8-96ff-05sdsadd",
"cust_id": "abc#gmail.com"
}
How do I ensure that the txnid transaction id is not repeated i.e. if I use the same transaction id twice then there should be an error thrown?
I was planning to save each transaction id to customer id map in a table, query the table to check if the transaction id is unique. Is this an efficient method?
Or is there any other efficient/simpler method to achieve the same?
You solution is fine, but the downside is database might not be the source of truth for txnid. Lets say txnid is present is saved in api but saving in database failed.
I would suggest the following solution:
Query the api for txnid on the fly (assumption: an api to provide the response HTTP.OK 200 if the txnid is present or else HTTP.NOT_FOUND 400). The api will be the only source of truth in this case.
When using #Cacheable annotation(org.springframework.cache.annotation.Cacheable) on the repository with custom key like name,getting the issue of running extra query on id field on every consecutive request.
See the repository code below:
public interface StatusRepository extends JpaRepository<Status, Integer> {
#Cacheable(value = "StatusByStatusNameCache" , key="#statusName")
public Status findByStatusName(String statusName);
}
Above you can see that a cache is defined for status name only, now after running first request got the following Hibernate console with query on status name:
Hibernate: select status0_.status_id as status_i1_7_, status0_.status_name as status_n2_7_ from status status0_ where status0_.status_name=?
Hibernate: select event0_.event_id as event_id1_3_, event0_.event_name as event_na2_3_ from events event0_ where event0_.event_name=?
now then hit another second request getting hibernate query in console with id :
Hibernate: select event_.event_id, event_.event_name as event_na2_3_ from events event_ where event_.event_id=?
Hibernate: select requestcha_.request_channel_id, requestcha_.request_channel_name as request_2_6_ from request_channels requestcha_ where requestcha_.request_channel_id=?
Hibernate: select status_.status_id, status_.status_name as status_n2_7_ from status status_ where status_.status_id=?
I don't understand why this extra query is firing as status_name query is cached but how to stop this id query on every consecutive call after first request.
The #Cacheable annotation by Spring is completely independent from the any cache provided by Hibernate/your JPA implementation.
The query by id will not be prevented by caching the result of the by name query, because the caching for the id query would be done by JPAs first level cache, which doesn't know or care about Springs cache.
Here is what is probably going on:
findbyName
entity is in 1st level cache and in Springs cache.
Any access by id (e.g. navigating to the entity)
entity gets served from 1st level cache.
session ends.
entity is removed from 1st level cache
findByName
entity is served from Springs cache. Note that this is now a detached entity. Nothing is in the 1st level cache.
access by id
entity is loaded from database, since it is not found in the 1st level cache.
You should enable Hibernates 2nd level cache to cache entities across sessions for access by id.
I also would advise against combining the caches of JPA/Hibernate with Spring Caches and rather use JPAs own query cache to cache findByName. See Spring JPA Hibernate query cache doesn't work for how to make it work with Spring Data JPA.
Also take a look at this article by Vlad Mihalcea about interaction of query cache and 2nd level cache.
Note that Oliver Drotbohm seems to have a different opinion.
Getting stuck while making transaction on composer-playground. Github Link. It throws the error
t: Instance org.hcsc.network.Commodity#ts1 has property company with type org.hyperledger.composer.system.NetworkAdmin that is not derived from org.hcsc.network.Trader
In your definition of Trace you have a --> Trader company, and in your code you assign me (current participant) - BUT you have processed the transaction using an ID that is bound to the Network Admin (org.hyperledger.composer.system.NetworkAdmin)
You need to run the transaction as a Trader
Create a new Trader participant
Issue an ID to the participant
Select and use that ID
Run the transaction
BTW I notice that you are using a new Date(); in your transaction - this is an example of a 'non-deterministic' value, and when you move to a multi-peer configuration this will fail. It will fail because when the Fabric runs the transaction on Multi-peer and tries to find consensus, the timestamps will be fractionally different on each peer and the transaction will be rejected. For the same reason you can't use random numbers in transactions.
1) Does inventory material transaction ID get populated when any standard transaction is made in oracle install base.
2) I defined a custom transaction type and passing that to public API,at that time material transaction ID is not getting populated.
Please let me know whether material transaction ID is populated only to standard transactions or also for custom transactions
For each and every transaction done in Inventory material transaction ID is populated that you can check in Inventory >> transactions >> material transactions..