I'm new to Hibernate and am working with an Oracle 10g database. We have columns in our tables that are of type TIMESTAMP WITH TIMEZONE. Hibernate does not seem to support this mapping directly. Is there a standard way to go about this?
An example of a UserType storing java.util.Calendar with time zone information is given in this blog post: http://www.joobik.com/2010/12/mapping-dates-and-time-zones-with.html
TIMESTAMP WITH TIMEZONE is Oracle extension and thus is not supported by Hibernate out of the box. You have two options:
1) Change your table structure to store timezone in a separate column (as VARCHAR2). Hibernate is able to map java.util.TimeZone as timezone type using its ID.
2) Write a custom class to hold both timestamp and timezone and a custom UserType that would persist it. It will have to be a CompositeUserType if you need the ability to use its individual properties (e.g. timezone or timestamp) in queries. Look at this example to get you started; you'll need to alter it to actually store the timezone.
Related
Here is the spring data oracle nosql persistence model link:
https://docs.oracle.com/en/database/other-databases/nosql-database/20.3/java-driver-table/persistence-model.html
In the Student entity shown in the image/from link, firstName and lastName fields are not getting created as key-value fields, instead, a kv_json JSON field is created and the firstName and lastName fields schema is present in the kv_json field.
As per the documentation,
the fields apart from the primary key will be mapped to a single JSON
field named kv_json
I want to disable this feature of having kv_json JSON filed and want to have all java fields in the entity as columns directly like the id field in the oracle NoSQL table.
Is there any solution to achieve this?
For a basic reference of Spring with Oracle NoSql: https://github.com/oracle/nosql-spring-sdk
Yes. This is confirmed. There is no way to do the mapping to a fixed schema or an existing schema. Please refer to this link with the new documentation for more information: https://github.com/oracle/nosql-spring-sdk/blob/main/README.md
When performing migration of legacy data to a springboot project it is sometimes crucial, to use the same Date for auditing fields such as createdDate and lastModifiedDate.
When using mongodb auditing, it is possible to override the createdDate with a custom date using #CreatedDate annotation.
However, the same is not true for #LastModifiedDate.
Mongodb auditing always saves the document with the actual Date the document was modified on instead of overriding it with the provided date.
Using #LastModifiedDate is there a way to save LastModifiedDate with the provided date similar to when using #CreatedDate?
Thanks
I want to query all instances of a model by the most recently created.
Reading the official docs, they suggest a way of querying by the default timestamps (updatedAt/createdAt) but only when also querying by another key. So I know I could query a hypothetical User model by name and createdAt, but I can't query all instances of User by createdAt.
Is there an established way of doing this?
I have tried adding a #key directive to sort by updatedAt, but that results in an error because updatedAt is automatically added and not described in my schema. If I then add the timestamps to my schema this creates problems when mutating clients because it expects the timestamps to be added by me, which I obviously don't do because it's automatically added by DynamoDB.
Thanks
You could try using a Global Secondary Index on the field you want to query. In your AppSync resolver, you need to specify the index you want to use for the query.
Another way would be to run a scan operation against your DB (you don't need to specify a key in this case), although that would be way more inefficient than a GSI.
When i try to save an entity that contains with a Calendar object i get the following error.
'class java.util.GregorianCalendar' is not a registered #Subclass"
I want to be able to store a time stamp with my entity. Storing the time as a string works but id like to keep it as an object if possible.
Is there something specific i need to do to be able to store a Calendar object with objectify?
If i can not store a Calendar object, what is the best alternative for storing a timestamp with objectify(hopefully using standard java classes)?
java.util.Date is a good choice.
I need to set date column with current date time whenever related entity or table has been updated using nHibernate?
You can use Interceptors as described here http://nhibernate.info/doc/nh/en/index.html#objectstate-interceptors
The example given on this page will solve your problem if you use the event "OnFlushDirty"