persistence

Can not find the declaration of element 'persistence'

拈花ヽ惹草 提交于 2019-11-27 02:41:09
问题 Have put the persistence.xml in the classpath of the project in eclipse because before the error was that the file was not found. Now gives this error: Caused by: javax.persistence.PersistenceException: Invalid persistence.xml. Error parsing XML [line : -1, column : -1] : cvc-elt.1: Can not find the declaration of element 'persistence' <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" xsi:schemalocation="http://java

Is there a way to change the JPA fetch type on a method?

夙愿已清 提交于 2019-11-27 02:14:52
问题 Is there a way to change the JPA fetch type on a single method without editing the entity object? I have a shared ORM layer consisting of JPA entity classes. This ORM layer is accessed by two DAO layers. One DAO needs lazy fetching, as it is for my web application, the other needs eager fetching, as I need it to be threadsafe. Here is an example method from my threadsafe DAO, @PersistenceContext(unitName = "PersistenceUnit", type = PersistenceContextType.TRANSACTION) private EntityManager em;

A JTA EntityManager cannot use getTransaction()

。_饼干妹妹 提交于 2019-11-27 02:07:59
问题 How do I have the following code in my non-ejb application. The code works. @Override public void saveItems(Collection<T> items) { synchronized (em) { EntityTransaction tx = em.getTransaction(); try { tx.begin(); for (T item : items) { saveItem_((Class<T>) null, item); } tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } } } } In a new application I'm using EJB3 + JSF and would like to re-use the library containing the code above. My peristence unit for the new application looks

Core Data Store included in App Bundle

依然范特西╮ 提交于 2019-11-27 01:58:42
问题 I can't find a clear description of these steps in Apple docs... I have a xcdatamodeld in my xcode project At launch time, my app parses a XML (project resource) to fill the Core Data Store (SQLLite) During lifetime of my app, I add, remove, update data of that Store Now, I want to stop doing that heavy XML parsing process on device and directly include a Store containing the required data. I have some questions regarding this : Can I fill a store with a OS X app and then include this store

On using Terracotta as a persistence solution

情到浓时终转凉″ 提交于 2019-11-27 01:53:34
问题 Would it be a good idea to use Terracotta as a persistence solution (replacing a database)? I'm specifically wondering about data integrity issues and support for transactional systems. 回答1: Terracotta is transactional (synchronized blocks form transactions of modified objects) but is not and doesn't want to be JTA-compliant. There is a fairly lengthy discussion of transactions and some common misconceptions about Terracotta here. I wrote a blog post about data lifetimes and how that should

How to store persistent data client side

爷,独闯天下 提交于 2019-11-27 01:40:41
问题 I need to programmatically store data on the client side without having to transfer the data from the server on every page load. I considered generating a dynamic JavaScript file with the needed data for the current session of the user and make sure it is cached, but that seems really messy and there are a few drawbacks I can think of to such an approach. How can I go about storing persistent data on the client side? 回答1: You may store data in window.name , which can hold up to 2MB of data (!

Hibernate @OneToMany with mappedBy (parent-child) relationship and cache problem

别说谁变了你拦得住时间么 提交于 2019-11-27 01:29:40
问题 I have this problem for a long time now, I have searched the web and SO in and out and didn't find a solution yet. I hope you can help me on that. I have a parent-child relationship between two entities like the following: @Entity public class Parent { // ... @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) private Set<Child> children = new HashSet<Child>(); // ... } @Entity public class Child { // ... @ManyToOne(fetch = FetchType.LAZY) private Parent

how to make a composite primary key (java persistence annotation)

你。 提交于 2019-11-27 01:27:56
How to make it so that the table user_roles defines the two columns (userID, roleID) as a composite primary key. should be easy, just can't remember/find. In user entity: @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "user_roles") public List<RoleDAO> getRoles() { return roles; } @Id @GeneratedValue(strategy = GenerationType.AUTO) public Integer getUserID() { return userID; } In roles entity: @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "user_roles") public List<UserDAO> getUsers() { return users; } @Id @GeneratedValue(strategy = GenerationType.AUTO) public Integer getRoleID()

Persist variable changes between tests in unittest?

纵饮孤独 提交于 2019-11-27 01:13:48
问题 How do I persist changes made within the same object inheriting from TestCase in unitttest? from unittest import TestCase, main as unittest_main class TestSimpleFoo(TestCase): foo = 'bar' def setUp(self): pass def test_a(self): self.assertEqual(self.foo, 'bar') self.foo = 'can' def test_f(self): self.assertEqual(self.foo, 'can') if __name__ == '__main__': unittest_main() I.e.: I want those two tests above to pass 回答1: As some comments have echoed, structuring your tests in this manner is

Generating a globally unique identifier in Java

别说谁变了你拦得住时间么 提交于 2019-11-27 01:04:41
Summary: I'm developing a persistent Java web application, and I need to make sure that all resources I persist have globally unique identifiers to prevent duplicates. The Fine Print: I'm not using an RDBMS, so I don't have any fancy sequence generators (such as the one provided by Oracle) I'd like it to be fast, preferably all in memory - I'd rather not have to open up a file and increment some value It needs to be thread safe (I'm anticipating that only one JVM at a time will need to generate IDs) There needs to be consistency across instantiations of the JVM. If the server shuts down and