persistence

How to use JDO persistence manager?

北城以北 提交于 2019-11-26 18:27:25
问题 I have two questions regarding how to create / use the JDO persistence manager (PM, hereafter). Say, in a Java web application, if I have 10 entities, which can be logically grouped into 2 groups (for example, 5 user related entities and 5 business related entities) Should I need two different PMs to manage these 2 groups or only one PM is enough? Regarding the initialization, shall I use singleton instance of a PM (which will be shared by all the user's using the app at a given point of time

JPA/Hibernate bulk(batch) insert

点点圈 提交于 2019-11-26 18:13:27
问题 Here is simple example I've created after reading several topics about jpa bulk inserts, I have 2 persistent objects User, and Site. One user could have many site, so we have one to many relations here. Suppose I want to create user and create/link several sites to user account. Here is how code looks like, considering my willing to use bulk insert for Site objects. User user = new User("John Doe"); user.getSites().add(new Site("google.com", user)); user.getSites().add(new Site("yahoo.com",

Correct use of flush() in JPA/Hibernate

只愿长相守 提交于 2019-11-26 18:12:05
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 auto-generated IDENTITY field recordId . This recordId should be written to entity B as a foreign-key to A

PersistenceUnit vs PersistenceContext

梦想与她 提交于 2019-11-26 17:59:29
问题 In few project I have been successfully using @PersistenceUnit(unitName = "MiddlewareJPA") EntityManagerFactory emf; ... EntityManager entityManager = emf.createEntityManager(); to obtain EntityManager for Database connection, but some days ago I was trying to move my project to Jboss EAP 6.2 and it couldn't create EntityManager . I was googling it and I found that I should try change @PersistenceUnit to @PersistenceContext(unitName = "MiddlewareJPA") private EntityManager entityManager; to

How do I encode enum using NSCoder in swift?

六眼飞鱼酱① 提交于 2019-11-26 17:39:16
Background I am trying to encode a String-style enum using the NSCoding protocol, but I am running into errors converting to and back from String. I get the following errors while decoding and encoding: String is not convertible to Stage Extra argument ForKey: in call Code enum Stage : String { case DisplayAll = "Display All" case HideQuarter = "Hide Quarter" case HideHalf = "Hide Half" case HideTwoThirds = "Hide Two Thirds" case HideAll = "Hide All" } class AppState : NSCoding, NSObject { var idx = 0 var stage = Stage.DisplayAll override init() {} required init(coder aDecoder: NSCoder) { self

How to make offline database for my app?

懵懂的女人 提交于 2019-11-26 16:57:39
问题 I am getting problem in consuming RestAPI and saving offline data. Is any one have best ideas about this. I want to save JSON response from server in local database and use that data when no internet is available. like Firebase realtime Database. 回答1: I think what are you asking for is a mechanism to persist data into your application. There are several approaches to achieve this. Although it could be too broad to provide detailed answer, you might want to check as options: Databases: Core

How to inject persistence context to different data source programmatically

二次信任 提交于 2019-11-26 16:29:32
问题 In standard EJB 3, when injecting entity manager, persistence unit (which refers to datasource) is hardcoded into annotation: (or alternatively xml file) @PersistenceContext(unitName = "myunit") private EntityManager entityManager; Is there a way to use an entity manager but to select data source by name at runtime? 回答1: Using EclipseLink, You can set a DataSource configured in your app server. import org.eclipse.persistence.config.PersistenceUnitProperties; ... .... Map props = new HashMap()

How to load a separate Application Settings file dynamically and merge with current settings?

爷,独闯天下 提交于 2019-11-26 16:18:42
问题 There are questions pertaining to reading settings from a separate config file and others similar to it, but my question is specific to application property settings (i.e. <MyApplication.Properties.Settings> - see XML file below) and how to load them dynamically. I tried the method in this post, which involved refreshing the entire appSettings section of the main config file, but my adaptation threw exceptions because I wasn't replacing the appSettings section: var config =

How to save data in iOS

前提是你 提交于 2019-11-26 16:07:25
问题 I'm making a game and when I close the app (close at multitask manager), all my data is gone! So, My question is very simple: How do I save the data? 回答1: Let's say you want to save score and level, which are both properties of an object called dataHolder. DataHolder can be created as a singleton, so you don't have to worry too much about from where you access it (its sharedInstance actually): It's code would look a bit like this: DataHolder.h #import <Foundation/Foundation.h> @interface

When to use DiscriminatorValue annotation in hibernate

僤鯓⒐⒋嵵緔 提交于 2019-11-26 16:04:13
问题 What and when is the best scenario to use DiscriminatorValue annotation in hibernate? 回答1: These 2 links help me understand the inheritance concept the most: http://docs.oracle.com/javaee/6/tutorial/doc/bnbqn.html http://www.javaworld.com/javaworld/jw-01-2008/jw-01-jpa1.html?page=6 To understand discriminator, first you must understand the inheritance strategies: SINGLE_TABLE, JOINED, TABLE_PER_CLASS. Discriminator is commonly used in SINGLE_TABLE inheritance because you need a column to