persistence

Hibernate saveOrUpdate vs update vs save/persist

三世轮回 提交于 2019-12-03 06:45:28
I am struggling to apprehend the slight differences between the hibernate methods saveOrUpdate - update - save/persist . I know there are some similar questions on the site: What are the differences between the different saving methods in Hibernate? Difference between save and saveOrUpdate method hibernate but having read them, I did not notice an answer covering all the issues coming from using those methods in any case. I would to mention the example I have created to test: I have a table USER with the records: id | company 1 Company1 2 Company2 I execute then the code: Session session =

Hibernate like layer for C++

大城市里の小女人 提交于 2019-12-03 06:39:26
Using a DB with C++ is a real mess and it was refreshing when I moved to Java to be able to use a unified system to abstract the whole layer away (aka Hibernate). There are a couple of C++ abstract layers for DB's out there but they are usually vendor specific and only a thin layer that wraps the real C API. Has anybody come across something more like hibernate for C++ or know of a group or open source project that is looking at this problem domain. I don't know of any C++ library like Hibernate, but certainly there are non-vendor specific libs: SOCI and DTL We developed an open source library

Persistent memoization in Python

巧了我就是萌 提交于 2019-12-03 06:23:20
I have an expensive function that takes and returns a small amount of data (a few integers and floats). I have already memoized this function, but I would like to make the memo persistent. There are already a couple of threads relating to this, but I'm unsure about potential issues with some of the suggested approaches, and I have some fairly specific requirements: I will definitely use the function from multiple threads and processes simultaneously (both using multiprocessing and from separate python scripts) I will not need read or write access to the memo from outside this python function I

Creating a composite Unique constraints on multiple columns

China☆狼群 提交于 2019-12-03 06:11:42
问题 This is my model: class User {...} class Book { User author; int number; } Every book number starts at 1 per author and increments upwards. So we'll have Books 1,2,3 by John Grisham, Book 1..5 by George Martin, etc... Is there a unique constraint I can place on Book , that would guarantee we don't have two books with the same number by the same author? Similar to @Column(unique = true) , but the constraint only applies on the composite of Author X number ? 回答1: Use @UniqueConstraint: @Table(

Why do we have to manually flush() the EntityManager in a extended PersistenceContext?

我的梦境 提交于 2019-12-03 05:16:09
问题 In our J2EE application, we use a EJB-3 stateful bean to allow the front code to create, modify and save persistent entities (managed through JPA-2). It looks something like this: @LocalBean @Stateful @TransactionAttribute(TransactionAttributeType.NEVER) public class MyEntityController implements Serializable { @PersistenceContext(type = PersistenceContextType.EXTENDED) private EntityManager em; private MyEntity current; public void create() { this.current = new MyEntity(); em.persist(this

Quick'n'dirty persistence [closed]

你说的曾经没有我的故事 提交于 2019-12-03 05:04:24
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I often find myself needing a quick ( in terms of code ), lightweight ( in term of runtime, dependencies) persistence solution for simply a bunch of objects, mainly between application restarts. Usually I resort to some Java serialisation hack, but I wonder if there's something better out there. Have you used

javax.persistence.Entitymanager: remove() method

六眼飞鱼酱① 提交于 2019-12-03 04:21:30
问题 Does remove (Object entity) method of EntityManager work only on those objects got from find () method? I have following code snippet: public void deletePerson() { EntityManager em = getEntityManager(); Person p = new Person("x", "y", 200); em.remove(p); } But it is not removing the particular entry from database. When I tried something like below: public void deletePerson() { EntityManager em = getEntityManager(); Person p = em.find(Person.class, 200); em.remove(p); } It's working fine. 回答1:

Is closing and reopening Realm instances bad for performance?

浪尽此生 提交于 2019-12-03 03:54:10
When using SQLite I usually have a single SQLiteOpenHelper instance per application and I never ever close it, since its database is used continuously by many other classes and closing/reopening it would be slower and more complicated. Now I'm toying with Realm and I'm planning to access Realm instances only from Data Access Objects. Every call will be made from a worker thread. I've been reading the examples and they usually call getInstance/close per Activity or background task. Since Realm persists the data in a file like SQLite, is it a good idea to call getInstance/close for each

How would one make Python objects persistent in a web-app?

安稳与你 提交于 2019-12-03 03:34:16
I'm writing a reasonably complex web application. The Python backend runs an algorithm whose state depends on data stored in several interrelated database tables which does not change often, plus user specific data which does change often. The algorithm's per-user state undergoes many small changes as a user works with the application. This algorithm is used often during each user's work to make certain important decisions. For performance reasons, re-initializing the state on every request from the (semi-normalized) database data quickly becomes non-feasible. It would be highly preferable,

How to insert images in mongoDB using java?

五迷三道 提交于 2019-12-03 03:31:06
问题 I want to store image documents in MongoDB. I am using java. Any links or suggestions would be appreciated. 回答1: For storing binary data like images you can use GridFS or implement your own realization; Download the driver and look at src/test/com/mongodb/gridfs/GridFSTest.java ;) Edit: you are lucky today! I made complete code for you;) Enjoy! package mongodb.testing.java; import com.mongodb.*; import com.mongodb.gridfs.*; import java.io.*; public class Main { public static byte[] LoadImage