persistence

Easiest way to persist a data structure to a file in python?

青春壹個敷衍的年華 提交于 2019-11-26 22:08:27
Let's say I have something like this: d = { "abc" : [1, 2, 3], "qwerty" : [4,5,6] } What's the easiest way to progammatically get that into a file that I can load from python later? Can I somehow save it as python source (from within a python script, not manually!), then import it later? Or should I use JSON or something? Use the pickle module. import pickle d = { "abc" : [1, 2, 3], "qwerty" : [4,5,6] } afile = open(r'C:\d.pkl', 'wb') pickle.dump(d, afile) afile.close() #reload object from file file2 = open(r'C:\d.pkl', 'rb') new_d = pickle.load(file2) file2.close() #print dictionary object

Generate JPA 2 Entities from existing Database

匆匆过客 提交于 2019-11-26 21:56:07
How can I generate JPA2 compliant @Entity from existing Databases?. I found this: Question Still its not clear if JBoss will generate compliant JPA2 and also I would like to know if there is a vendor independent way to do this. You can use a plugin like Eclipse Dali to do the trick for you. You can refer to the documentation, section 3.11 Generating Entities from Tables . I do not know of any specific vendor independent tool to do this, though. Try using OPENJPA Reverse mapping tools. They offer lot more facility and are easy to configure. This example would clarify. If you are using maven as

what is the right path to refer a jar file in jpa persistence.xml in a web app?

爱⌒轻易说出口 提交于 2019-11-26 20:35:53
persistence.xml looks like this: <persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <non-jta-data-source>jdbc/test</non-jta-data-source> <jar-file>../../lib/app-services-1.0.jar</jar-file> <exclude-unlisted-classes>false</exclude-unlisted-classes> </persistence-unit> It is a web project, so the deployment unit is a war file. The jar file I tried to refer is in WEB-INF/lib/ folder , persistence.xml is in WEB-INF/classes/META-INF folder. When being deployed, it simply tells me "WARNING: Unable to find file (ignored):

Creating a JSON Store For iPhone

余生长醉 提交于 2019-11-26 20:14:24
We have loads of apps where we fetch data from remote web services as JSON and then use a parser to translate that into a Core-Data model. For one of our apps, I'm thinking we should do something different. This app has read-only data , which is volatile and therefore not cached locally for very long . The JSON is deeply hierarchal with tons of nested "objects" . Documents usually contain no more than 20 top level items, but could be up to 100K. I don't think I want to create a Core Data model with 100's of entities, and then use a mapper to import the JSON into it. It's seems like such a song

One-To-Many Relationship with Join Table

时光总嘲笑我的痴心妄想 提交于 2019-11-26 19:57:17
问题 I have a one-to-many relationship modeled using join table: create table t1 (id int primary key, name varchar(10) /*...*/); create table t2 (id int primary key, name varchar(10) /*...*/); create table t1_t2 (t1_id int, t2_id int, primary key (t1, t2)); The tables are supposed to model the relationship of one t1 to many t2. What is the right way to model these tables using JPA? 回答1: The typical table for one T1 to many T2 is to have a foreign key on T2 pointing toward T1. The T1_T2 table is

Sharing a persistence unit across components in a .ear file

混江龙づ霸主 提交于 2019-11-26 19:43:58
In a Java EE 6 application where I'm using .ear packaging, I'd like to create a persistence unit that can be accessed from components in different .jar files. However, I'm not sure how to define this persistence unit. With the @PersistenceContext annotation the lookup only succeeds if the name matches a persistence unit defined in the local persistence.xml file. Is it possible to refer to external persistence units? Pascal Thivent Here are the relevant sections of the JPA 2.0 specification: 8.2 Persistence Unit Packaging ... A persistence unit is defined by a persistence.xml file. The jar file

Hibernate: “Field 'id' doesn't have a default value”

ぃ、小莉子 提交于 2019-11-26 19:40:24
I'm facing what I think is a simple problem with Hibernate, but can't solve it (Hibernate forums being unreachable certainly doesn't help). I have a simple class I'd like to persist, but keep getting: SEVERE: Field 'id' doesn't have a default value Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [hibtest.model.Mensagem] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91) [ a bunch more ] Caused by: java.sql.SQLException:

Persisting data suited for enums

时光怂恿深爱的人放手 提交于 2019-11-26 19:29:49
问题 Most projects have some sort of data that are essentially static between releases and well-suited for use as an enum, like statuses, transaction types, error codes, etc. For example's sake, I'll just use a common status enum: public enum Status { ACTIVE(10, "Active"); EXPIRED(11, "Expired"); /* other statuses... */ /* constructors, getters, etc. */ } I'd like to know what others do in terms of persistence regarding data like these. I see a few options, each of which have some obvious

Using javafx.beans properties in model classes

扶醉桌前 提交于 2019-11-26 18:55:44
Is it a correct practice to use JavaFX beans properties in the model classes? I wonder if it is a good practice to use properties in model classes to be able to bind them easier with the view components. I'm not worried about the availability of those libraries in future because my program will be run on JRE8 or later but the nature of using the JavaFX libraries in the model classes make me skeptical and I'm worried about current and future incompabilities specially because I want to use Hibernate to persist those attributes. Note: I use a pure JavaFX environment and I will never need Swing

Hibernate Vs iBATIS [closed]

无人久伴 提交于 2019-11-26 18:43:05
问题 For our new product re-engineering, we are in the process of selecting the best framework from Java. As the consideration is to go for database agnostic approach for model, we are working on options between Struts + Spring with iBATIS or Hibernate. Please advice which is best as both offer persistence. 回答1: Ibatis and Hibernate are quite different beasts. The way I tend to look at it is this: Hibernate works better if your view is more object-centric . If however you view is more database