Grails 3 (unsaved) instance issue while fetching from database (GORM) - grails-orm

I am getting an issue while fetching from the database using GORM like
UserRole.findByUser(User.first())
or using any kind of dynamic finders for fetching object.
It is always returning an object in an Unsaved state.
com.tothenew.cat.UserRole : (unsaved)
Can anyone explain why this is happening.

Related

JOOQ record caching exception

I am trying to cache JOOQ record result using redis. But the same is throwing the following error:
org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: org.jooq.impl.Utils$Cache$Key
Any suggestion how to fix this?
This seems to be the same issue as https://github.com/jOOQ/jOOQ/issues/5290, which is a bug in jOOQ 3.8.1
I can see two workarounds around this issue:
You explicitly "detach" your records prior to serialisation in redis by calling Record.detach()
You turn off automatic attaching of records to the creating Configuration using the Settings.attachRecords property
In both cases, should you wish to retrieve a record from redis and store it again, you will need to explicitly call Record.attach(Configuration)

No entities found after EntityCollection(Of TEntity).Add execution

I am working on VB.NET project using Entity Framework 4.
When I create new entity and add it to context.EntityCollection, without calling context.SaveChanges I cannot found newly added entity in that collection.
I need to check for duplicate records before saving to database and it appears that only working solution is to store entities in some dictionary outside of whole EF-generated stuff for checking duplicate records.
Is there any better solution?
Checking database directly before saving changes is possible solution.

See what is changed before executing context.SaveChanges()

In Entity Framework 5, Database-first, I am getting the error message
error in saving entities which do not make foreign key properties available
when I am trying to save a single object .
I don't know if there is a problem with the definition and mappings of a field of my object, or if I have a wrong reference in there and the Framework is somehow expecting me to provide objects for the 0...N objects my object-to-save could be referencing.
How do I see what changes are going to be written? I used a library to show the SQL which is going to be sent to the database, but it seems like the error is thrown before EF tries to execute an SQL command.

In Rails Test changes to objects not reflecting in Database?

I have a Rails 3 application, in which I am trying to write a test-case? When the test case loads, I can see that it is creating the objects corresponding to the fixtures in the database. However, if I change the object within the test case or create another object they do not reflect in the database. Further, if I find the newly created object that is happening correctly.
What is happening here? Also, how can I get the changes to reflect in the database?
In your test_helper.rb, the use_transactional_fixtures option is probably set to true. This means that every test is wrapped in a database transaction. A transaction (in MySQL InnoDB) has to be persisted with a "COMMIT". The rails testing framework just doesn't do that so your database is in a fresh state after each test. As a consequence, your changes are rolled back.
Changes within a transaction can only be seen by the database connection that started it, from the outside (in your case the rails db command) they won't show up.
I hope, this helps.

Should I use Get or Load - nhibernate?

I am wondering which one I should use in this situation. I have a dropdown list that send a value back to the server. The server currently uses load and make the object. It then grabs a value out of and tries to convert it to an enum.
After doing some reading it seems that I should just use Get as I am need to access something out of the object other than the PK.
In general, use Get if you need access to properties other than the Id itself; this makes the intention of your code much clearer and is likely more efficient in the long run. Load is great if you need to setup FK relationships when creating or updating entities without making unnecessary round-trips to the database.
For further reading, check out Ayende's article that describes this in greater detail.
Get and Load are different if lazy loading is enabled.
If you use the method Load, NHibernate does not retrieve the entity from the database, but rather creates a proxy object and the only populated property is the ID.
If you access to an other property, NHibernate will load the entity from the DB.
So in your case the best use should be Get.