postgresql - rails store java object to postgres -


i running rails4 using jruby , postgres db. have jar file call create instance of java object. java object bridge backend calculation engine on different machine. queries calculation engine , stores return values instance variables. need keep unique instance of object per session. possible store instances of java object in postgres? have no idea start on , looking on google hasn't helped advice appreciated. thanks.

is possible store instances of java object in postgres?

yes, it's bad idea.

if must...

if want this, can use java's serialization framework byte[] representation of object, can stored in bytea field in postgresql database via pgjdbc. i'm sure rails has mechanism work binary data too, if you'd prefer via rails.

better ways objects that're data containers

if object doesn't have logic, if it's bunch of instance variables no interesting methods act on them, should map object fields in relation, save each instance variable field. provide constructor reverse.

an alternative instead serialize standard-ish format json , store that in database. give object tojson , fromjson methods manually, or use jaxb serialize/deserialize it. (jaxb uses xml, , can use that, or can add json support plugins).

better true objects logic

if object "business object", i.e. manages data , has logic , rules, might want consider remote access instead.

in conventional java world you'd instead using remoting, remote procedure calls instance running on main machine, wrapping instance in ejb3 , generating ejb3 client stub transparently talk it.

a more modern (imo) , simpler write (though more verbose use) approach use jax-rs provide simple web service interface can use talk object remotely.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -