persistence

Is it possible to get gVim to remember window size?

戏子无情 提交于 2019-12-02 18:50:20
I know how to set the initial window size in gVim, but how do I get it to automatically restore the window dimensions from last session? Is this even possible? Edit: Corrected my answer. The mentioned winsize sessionoption only refers to the vim internal window layout, not the external dimensions. If you use :mksession and load the session on vim startup with gvim -S Session.vim you can include the window position and size into the session by including winpos and resize in the sessionoptions, see :help 'sessionoptions With autocommands you could even automate the saving and restoring of the

Creating a composite Unique constraints on multiple columns

一笑奈何 提交于 2019-12-02 18:41:46
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 ? Use @UniqueConstraint : @Table( uniqueConstraints= @UniqueConstraint(columnNames={"author_id", "number"}) ) @Entity class Book extends

javax.persistence.Entitymanager: remove() method

一曲冷凌霜 提交于 2019-12-02 18:38:36
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. Quoting from ObjectDB's manual on deleting JPA entity objects : In order to delete an object from the

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

狂风中的少年 提交于 2019-12-02 18:35: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.current); } public void load(Long id) { this.current = em.find(MyEntity.class, id); }

Quick'n'dirty persistence [closed]

若如初见. 提交于 2019-12-02 18:18:22
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 something similar? To make it clear, a JPA-based solution is not lightweight in my book, and a JDBC-based one is not quick . Update : I favour configuration-less frameworks over those which require configuration. For instance the Java serialisation solution requires a implements

NSFileManager: removing item

血红的双手。 提交于 2019-12-02 18:06:33
问题 The problem is removing an item that´s been written using writeToFile: method, I cannot seem to remove it. I tried NSFileManager but I guess these are two different types of storage. - (BOOL) removeObject: (NSString *)objectToRemove inCategory:(StorageType)category { BOOL result = NO; NSError *removeError; NSString *storageFolder = [self getCategoryFor:category]; if (objectToRemove) { NSFileManager *fileManager = [[NSFileManager alloc]init]; // Find folder NSArray *paths =

Why put a DAO layer over a persistence layer (like JDO or Hibernate)

我是研究僧i 提交于 2019-12-02 17:05:26
Data Access Objects (DAOs) are a common design pattern, and recommended by Sun. But the earliest examples of Java DAOs interacted directly with relational databases -- they were, in essence, doing object-relational mapping (ORM). Nowadays, I see DAOs on top of mature ORM frameworks like JDO and Hibernate, and I wonder if that is really a good idea. I am developing a web service using JDO as the persistence layer, and am considering whether or not to introduce DAOs. I foresee a problem when dealing with a particular class which contains a map of other objects: public class Book { // Book

How to insert images in mongoDB using java?

懵懂的女人 提交于 2019-12-02 17:01:19
I want to store image documents in MongoDB. I am using java. Any links or suggestions would be appreciated. Edward83 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(String filePath) throws Exception { File file = new File(filePath); int size = (int)file.length();

Refresh and fetch an entity after save (JPA/Spring Data/Hibernate)

ε祈祈猫儿з 提交于 2019-12-02 16:42:06
I've these two simple entities Something and Property . The Something entity has a many-to-one relationship to Property , so when I create a new Something row, I assign an existing Property . Something: @Entity @Table(name = "something") public class Something implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "name") private String name; @Column(name = "owner") private String owner; @ManyToOne private Property property; // getters and setters @Override public String toString() {

ehcache persist to disk issues

允我心安 提交于 2019-12-02 16:17:22
I want to do something with ehcache in Java that I think should be extremely simple, but I've spent enough time frustrating myself with the docs... Write a value to a disk persistent cache. Shut down. Start up again and read that value. Here is my Java function: private static void testCacheWrite() { // create the cache manager from our configuration URL url = TestBed.class.getClass().getResource("/resource/ehcache.xml"); CacheManager manager = CacheManager.create(url); // check to see if our cache exits, if it doesn't create it Cache testCache = null; if (!manager.cacheExists("test")) {