persistence

Should embeddable jpa class implement equals and hashCode?

拈花ヽ惹草 提交于 2019-12-05 10:15:40
Let's say I have the following scenario: @Entity public class Person { @Id private Long id; //Surrogate key @Embedded private Name name; //Natural key public int hashCode() { ... //based on natural key Name } public boolean equals(Object obj) { ... //based on natural key Name } } @Embeddable public class Name { private String firstName; private String middleName; private String lastName; //Should I implement equals/hashCode baseed on the three fields? } Should Name class implement equals and hashCode on Name class in order that Person equals work properly?. For an Embeddable object that will

Why do we need to specify class inside <persistence-unit> element?

丶灬走出姿态 提交于 2019-12-05 09:24:19
My persistence.xml has 2 persistence-units. Each of them has several <class> elements. I thought that we must specify all classes related to certain persistence-unit. But I accidentally forgot to specify class-element for new entity but the program worked fine even without it. Then I removed all class-elements and everything worked fine. So, why do we need it? sample code: <persistence-unit name="JiraManager" transaction-type="RESOURCE_LOCAL"> <class>chartdemo.model.domain.Category</class> </persistence-unit> If you didn't specify classes in the persistence.xml file your persistence manager

How to keep CheckBox persistence in Gridview Android (handling checkbox state)?

≡放荡痞女 提交于 2019-12-05 07:48:23
问题 I am working on an app where i am using custom gridview with images & checkboxes. Displaying of gridview with images & checkboxes is working good. But here my issue is after make one checkbox checked if i scroll the gridview another checkbox is checked & again if i scroll down again it is displaying. Here checkbox checked state was maintaing. My Adapterclass Code is.. MyGrid.java public class ImageAdapter extends BaseAdapter { private LayoutInflater mInflater; public ImageAdapter() {

How to prevent “Local transaction already has 1 non-XA Resource” exception?

时间秒杀一切 提交于 2019-12-05 04:02:23
I'm using 2 PU in stateless EJB and each of them is invoked on one method: @PersistenceContext(unitName="PU") private EntityManager em; @PersistenceContext(unitName="PU2") private EntityManager em2; @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW ) public void getCandidates(final Integer eventId) throws ControllerException { ElectionEvent electionEvent = em.find(ElectionEvent.class, eventId); ... Person person = getPerson(candidate.getLogin()); ... } @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW ) private Person getPerson(String login) throws ControllerException {

How should manage Database transactions using Entity Manager in a relatively large application?

走远了吗. 提交于 2019-12-05 02:43:16
问题 I have developed a fairly large CRUD application, using a MYSQL Database and Swing Application framework and javax.persistence. My question is how should I best manage my transactions given the javax.persistence.Entitymanager? Currently, I have one instance of Entity manager held by the Application class. It is passed to all requesting pages, which in turn use it to persist and merge entities. I start a transaction on application start-up, and commit (and restart) each time a change is made.

Best way to implement “Remember Me” check box in WinForms / WPF

匆匆过客 提交于 2019-12-05 02:28:17
问题 I want to add a "Remember Me" check box to the login form of my WPF App. What's the best way to do this? Currently the app logs in via a websevice call that returns an authenticated token that it uses for subsequent calls. Should I simply two-way encrypt and store this token somewhere in the files system? 回答1: You could also store it in Isolated Storage or create a User setting in your application's Settings. Edit: Oren's suggestion of using DPAPI to protect information is well and good, but

JPA @OneToMany and composite PK

若如初见. 提交于 2019-12-05 02:10:55
I am working on a JPA project. I need to use a @OneToMany mapping on a class that has three primary keys. You can find the errors and the classes after this. javax.persistence.PersistenceException: No Persistence provider for EntityManager named JTA_pacePersistence: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory: javax.persistence.PersistenceException javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions

JPA or Hibernate for Java Persistence?

血红的双手。 提交于 2019-12-05 00:02:09
I'm researching the development of Enterprise Applications in Java, .NET and Groovy. For each platform, we're going to try how hard it is to realize a simple SOAP web service. We'll use the tools and libraries that are most commonly used, to research the real world as accurately as possible. In this regard, when using Hibernate for persistence, would it better reflect the real world to use the new JPA (Java Persistence API), or the Hibernate custom API that existed before JPA came around? As you're probably already aware, as of 3.2 Hibernate is JPA certified. You can easily use Hibernate as

Is there a way to get all managed entities from an EntityManager

≯℡__Kan透↙ 提交于 2019-12-04 23:12:50
I'm setting up a basic test data util and want to keep track of all the data that the EntityManager handles. Rather than just having a bunch of lists for each entity is there a way to grab everything being managed by the EntityManager in one fell swoop? So instead of this: EntityManager em; List<Entity1> a; List<Entity2> b; ... List<Entityn> n; cleanup() { for(Entity1 e : a) em.remove(e); for(Entity2 f : b) em.remove(f); ... for(Entityn z : n) em.remove(z); } I want something like this; EntityManager em; cleanup() { List<Object> allEntities = em.getAllManagedEntities(); //<-this doesnt exist

Atomic state storage in Python?

纵然是瞬间 提交于 2019-12-04 21:32:18
I'm working on a project on an unreliable system which I'm assuming can fail at any point. What I want to guarantee is that if I write_state and the machine fails mid-operation, a read_state will either read a valid state or no state at all. I've implemented something which I think will work below -- I'm interested in criticism of that or alternative solutions if anyone knows of one. My idea: import hashlib, cPickle, os def write_state(logname, state): state_string = cPickle.dumps(state, cPickle.HIGHEST_PROTOCOL) state_string += hashlib.sha224(state_string).hexdigest() handle = open('%s.1' %