persistence

Correct use of flush() in JPA/Hibernate

≯℡__Kan透↙ 提交于 2019-11-26 06:14:36
问题 I was gathering information about the flush() method, but I\'m not quite clear when to use it and how to use it correctly. From what I read, my understanding is that the contents of the persistence context will be synchronized with the database, i. e. issuing outstanding statements or refreshing entity data. Now I got following scenario with two entities A and B (in a one-to-one relationship, but not enforced or modelled by JPA). A has a composite PK, which is manually set, and also has an

Persistent DB Connections - Yea or Nay?

喜你入骨 提交于 2019-11-26 05:57:57
问题 I\'m using PHP\'s PDO layer for data access in a project, and I\'ve been reading up on it and seeing that it has good innate support for persistent DB connections. I\'m wondering when/if I should use them. Would I see performance benefits in a CRUD-heavy app? Are there downsides to consider, perhaps related to security? If it matters to you, I\'m using MySQL 5.x. 回答1: You could use this as a rough "ruleset": YES , use persistent connections, if: There are only few applications/users accessing

How can I tell if another instance of my program is already running?

荒凉一梦 提交于 2019-11-26 03:57:41
问题 How do i tell if one instance of my program is running? I thought I could do this with a data file but it would just be messy :( I want to do this as I only want 1 instance to ever be open at one point. 回答1: You can create a Semaphore and stop execution (put the code into your *.dpr file) and bring you running application to the screen. var Semafor: THandle; begin { Don't start twice ... if already running bring this instance to front } Semafor := CreateSemaphore(nil, 0, 1, 'MY_APPLICATION_IS

Making data persistent in android

强颜欢笑 提交于 2019-11-26 03:48:16
问题 In my application,there are some application specific settings, which should be available to me , next time when my application starts up. In other words i want the data to be available across the sessions of an application cycle. Can this be achieved without using database(sqlite). 回答1: Many applications may provide a way to capture user preferences on the settings of a specific application or an activity. For supporting this, Android provides a simple set of APIs. Preferences are typically

Solve Hibernate Lazy-Init issue with hibernate.enable_lazy_load_no_trans

自古美人都是妖i 提交于 2019-11-26 03:32:48
问题 I have been suffering from infamous hibernate exception org.hibernate.LazyInitializationException: could not initialize proxy - no Session Now the community is cheering over <property name=\"hibernate.enable_lazy_load_no_trans\" value=\"true\"/> saying it solves the problem but USE IT WITH CAUTION . What they mean by use it with caution? What this property actually does? Please give me any insights. Thanks in advance. 回答1: The problem with this approach is that you can have the N+1 effect.

When to use EntityManager.find() vs EntityManager.getReference() with JPA

一个人想着一个人 提交于 2019-11-26 03:32:35
问题 I have come across a situation (which I think is weird but is possibly quite normal) where I use the EntityManager.getReference(LObj.getClass(), LObj.getId()) to get a database entity and then pass the returned object to be persisted in another table. So basically the flow was like this: class TFacade{ createT(FObj, AObj) { T TObj = new T(); TObj.setF(FObj); TObj.setA(AObj); ... EntityManager.persist(TObj); ... L LObj = A.getL(); FObj.setL(LObj); FFacade.editF(FObj); } }

What are the differences between the different saving methods in Hibernate?

狂风中的少年 提交于 2019-11-26 03:16:30
问题 Hibernate has a handful of methods that, one way or another, takes your object and puts it into the database. What are the differences between them, when to use which, and why isn\'t there just one intelligent method that knows when to use what? The methods that I have identified thus far are: save() update() saveOrUpdate() saveOrUpdateCopy() merge() persist() 回答1: Here's my understanding of the methods. Mainly these are based on the API though as I don't use all of these in practice.

Confusion: @NotNull vs @Column(nullable = false)

妖精的绣舞 提交于 2019-11-26 02:28:03
问题 When they appear on a field/getter of an @Entity , what is the difference between them? (I persist the Entity through Hibernate ). What framework and/or specification each one of them belongs to? @NotNull is located within javax.validation.constraints . In the javax.validation.constraints.NotNull javadoc it says The annotated element must not be null but it does not speak of the element\'s representation in the database, so why would I add the constraint nullable=false to the column? 回答1:

How persistent is localStorage?

只谈情不闲聊 提交于 2019-11-26 02:08:02
问题 I\'m depending heavily on localStorage for a plugin I\'m writing. All the user settings are stored in it. Some settings require the user the write regex\'es and they would be sad if their regex rules are gone at some point. So now I am wondering just how persistent the localStorage is. From the specs: User agents should expire data from the local storage areas only for security reasons or when requested to do so by the user. The above looks like it works just like cookies on the clientside. I

No Persistence provider for EntityManager named

守給你的承諾、 提交于 2019-11-26 01:21:01
问题 I have my persistence.xml with the same name using TopLink under the META-INF directory. Then, I have my code calling it with: EntityManagerFactory emfdb = Persistence.createEntityManagerFactory(\"agisdb\"); Yet, I got the following error message: 2009-07-21 09:22:41,018 [main] ERROR - No Persistence provider for EntityManager named agisdb javax.persistence.PersistenceException: No Persistence provider for EntityManager named agisdb at javax.persistence.Persistence.createEntityManagerFactory