Disable cache for one model - nhibernate

I got a table which is modified by two applications. One of them is using nhibernate. How do I disable caching for that table? Can it be done in the mapping file?

Cache is not enabled by default.
If you are referring to the "first level cache", i.e. the Session, there is something wrong with your usage pattern.

Assuming you have the L2 cache enabled for the session factory (via cache.use_second_level_cache), you should be able to exclude the <cache> element in your mapping file for that model.

Related

Per Infinispan Cache Properties

We have some generic code that operates on the caches in an Infinispan cache container. The code identifies certain caches for which a certain operation has to be performed by a custom property. The cache container and caches are configured through infinspan.xml or the Infinispan subsystem in WildFly.
Previously we would set a custom property on the datastore of the cache. With Infinispan 10+ this is no longer possible. We would have to implement a custom persistence store in order to set arbitrary properties on a cache. This seems like overkill especially since our caches are not persistent.
Is there a way to achieve this from an infinspan.xml, eg. without putting a custom object under a well known key in the cache?
Edit
The previous configuration looked something like this:
<local-cache name="stackoverflow-cache" configuration="default-configuration">
<data-container>
<property name="custom-property-key">custom-property-value</property>
</data-container>
</local-cache>
With version 10 of the Infinispan schema this is no longer supported.
I've made an example of how you can set some custom properties in the configuration here. It isn't trivial...
If you are using Infinispan server, you need a Jar with your classes and put it in server/lib folder.
Let me know if it fits your use case (I hope I didn't misunderstand it).
ps. since you control the parser, you can set your own XML structure if you want.

Apache Ignite: can I create cache tables manually, using DDL statements?

Speaking about the latest version (currently 2.3). Seems like old-way a little bit useless now.
If it is possible to create table(s) manually, here comes another question: how to map model POJO's fields and column names so I can fill in cache using DataStreamers. (#QuerySqlField.name, isn't it?)
If you are going to populate cache with data, using DataStreamer, then you should create it using Java API, or by configuring it in Ignite XML configuration.
Tables can be configured, using indexedTypes or queryEntities properties in CacheConfiguration. Take a look at the documentation: https://apacheignite.readme.io/docs/cache-queries#section-query-configuration-by-annotations

eclipselink without persistence.xml

I'm not a big fan of XML files. Therefore I'm wondering if there is a way to use eclipselink without its persistence.xml configuration file. Why?
Because I want to manage different databases dynamically. It would be much easier to do it without the XML file.
I'm surprised that I couldn't find anything on the web for now.
Not really, but you could create an EclipseLink ServerSession directly and wrap it with an EntityManagerFactoryImpl, but I would not suggest it.
You would be better off creating a persistence.xml. You can still do dynamic databases, you just need to pass a properties file to createEntityManagerFactory(Map) that include your database info.
Though it is not an direct answer to your question, this will help for the second part of your question. For managin multiple database connections, you can define multiple server sessions in sessions.xml and access those where you want.
you may use follwoing lines for accessing particular session
ServerSession aSession = = (ServerSession) SessionManager.getManager().getSession("session_2");

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.

NHibernate using single configuration file to connect to multiple dbs

I'd like to have a single configuration file and then when I'm creating a session change the hibernate-configuration->session-factory->connection.connection_string property to what I want it to be programmatically? Is it possible?
UPDATE:
I believe I may be able to do this like this
Configuration cfg = new Configuration();
cfg.Configure(sessionFactoryConfigPath);
cfg.Properties["connection.connection_string"] = ...
What I would wonder than, if that is ok, Is this a bad way to handle connecting to a different database for each session? if so why etc. I'd also like to know if/how you can open an nhibernate session with a .net connection object?
Use the ISessionFactory.OpenSession() overload that takes a IDbConnection.
That's how Castle's DifferentDatabaseScope does it.
I think it is better to use different configuration files per each data base just becouse you will be able to switch dialects very esasy.
You may also see this answer as it allows full configuration of session factories through one file. Configure NHibernate hibernate.cfg.xml file to have more connection strings