persist « Query « JPA Q&A





1. Where (which layer) to put Entity query methods, "persist" methods etc.?    stackoverflow.com

I have a SEAM app with some JPA/Hibernate entities. And I now wonder where to put my query, persistence methods. The default choice seems to put them in a session bean layer ...

2. Hibernate like layer for C++    stackoverflow.com

Using a DB with C++ is a real mess and it was refreshing when I moved to Java to be able to use a unified system to abstract the whole layer ...

3. What do REFRESH and MERGE mean in terms of databases?    stackoverflow.com

I'm curious and need to find this answer quick. Google won't help much. The Java Persistece API has these properties that tell the framework to cascade operations on associated entities:

CascadeType.PERSIST
CascadeType.DELETE
CascadeType.MERGE
CascadeType.REFRESH
I know what ...

4. Java Persistence: Cast to something the result of Query.getResultList()?    stackoverflow.com

Hey everyone, I'm new to persistence / hibernate and I need your help. Here's the situation. I have a table that contains some stuff. Let's call them Persons. I'd like to get all ...

5. JPA/Hibernate Query Returns Stale Results    stackoverflow.com

I am using an EXTENDED Persistent Context because it will allow me to Lazily Load a one-many relationship on an object and it also won't require a SELECT before I "merge" ...

6. Can javax.persistence.Query.getResultList() return null?    stackoverflow.com

And if so, under what circumstances? Javadoc and JPA spec says nothing.

7. How can I use the sql case clause in HQL?    stackoverflow.com

I really need help regarding this one. Here is the code snippet:

  hSql=" select case 
      when min(start_day_plan) is not NULL then min(start_day_plan)
   ...

8. Jpa query pulling from cache instead of database?    stackoverflow.com

I am hitting an issue with my Hibernate backed Jpa queries returning data that is not up to date. I assume it is an issue with pulling data from the cache ...

9. Is there any c++ persistent solution like java hibernate?    stackoverflow.com

Hello all correct me if i wrong but i don't know any solution in c++ that is similar to java persistent hibernate is there ?





10. exception in Persistence query    stackoverflow.com

I'm trying to retrieve a table using persistence framework the code i have written is in simple java class file in webapplication the code in the java class

EntityManager em = null;
   ...

11. Is it possible using JPA to stream results from javax.persistence.Query.getResultList()?    stackoverflow.com

I'm new to JPA and I'd like to know if it is possible to stream data from a result set, I mean I do not want to wait that the query ...

12. How to persist in order    stackoverflow.com

I have two entities: EXAM and EXAM_NORMAL. EXAM

@Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    private String name;
    private String codeName;
   ...

13. Hibernate persist order    stackoverflow.com

I have a question about how Hibernate persists entity relations. Let's say I have an entity A that has a relation with entity B and another one with entity C. I create an ...

14. JPA query for getting the whole tree    stackoverflow.com

I have a class which models all categories and they can be ordered hierarchically.

@Entity
@Table(name="categories")
public class Category {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sequence")
    @SequenceGenerator(name="sequence", sequenceName="categories_pk_seq", ...

15. How to find out efficiently the auto-generated id for a new object when using JPA?    stackoverflow.com

I have an attribute which is annotated with @Id. The ID is going to be generated automatically when persisting the object. That means that the ID-value is not defined before I ...

16. OpenJPA - not flushing before queries    stackoverflow.com

how can i set openjpa to flush before query. When i change some values in database i want to propagate these changes into application. I tried this settings in persistence.xml:

<property name="openjpa.FlushBeforeQueries" value="true" ...





17. Remove then Query fails in JPA/Hibernate (deleted entity passed to persist)    stackoverflow.com

I've got a problem with the removal of entities in my JPA application: basically, I do in this EJB Business method:

load photo list ;
for each photo {
    //UPDATE
 ...

18. hibernate to persist or just plain SQL query    stackoverflow.com

I am using hibernate for the first time for one of my projects. One of the entity is Education(StudentObject, CollegeObject, MajorObject, degreeString). To insert Education object into database, i've to load ...

19. JPA - getting distinct value from one column    stackoverflow.com

I have an entity that has few fields. One of them is city name. Now I want to get list of all distinct cities from that table. How can I archive ...

20. Hibernate bulk update leads to in-query which takes for ever to complete    stackoverflow.com

Article entity is a sub-class of the Product entity. The inheritance strategy for them is joined. Article#flag is a boolean attribute which I want to set false for all articles. Hence, ...

21. Persistence object cannot find persistence unit from persistence.xml    stackoverflow.com

Environment: Windows 7, NetBean 6.9 (the one including GlassFish v3, Java EE 6), MySQL server I've created tables in MySQL database and using NetBean's capability by right click on the project and ...

22. Can't find a persistence unit Error?    stackoverflow.com

Ii am using eclipse IDE. i am getting Can't find a persistence unit named 'manager1' Error JBOSS AS 6 is the server persistence.xml contains

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
 ...

23. Should I be trying to catch any EnityManager query exceptions?    stackoverflow.com

I usually layout my Java SE methods like this. Should I try to catch any exceptions for simple reads like this? I can see using catches for any inserts ...

24. Compile error because of "cannot find annotation method name() in type javax.persistence.Table"?    stackoverflow.com

all.
My project is not compiling,and giving these errors.

Information: D:\projects\gre\com\site\core\domain\Employee.class: warning: Cannot find annotation method 'schema()' in type 'javax.persistence.Table': class file for javax.persistence.Table not found.
...

25. Persisting Ordered Domain Objects    stackoverflow.com

A very common use case in many web applications is that domain objects can be ordered by a user in the web interface - and that order is persisted for later; ...

26. Query needed to check if an email already exist in a DB(Java Persistence API)    stackoverflow.com

I try to figure out what is the problem with this method that uses JPQL to validate if an email already exist in the DB, for some reason it does not ...

27. JPA: querying a view entity    stackoverflow.com

i'm having troubles with geting my tables to synchronize with a database. The main table in my application represents a mysql database view of two tables joined, and its bound to ...

28. Exception thrown when one parameter of an Oracle stored function is null    stackoverflow.com

I want o call a PL/SQL function using a named query. One of the parameters causes me problems. In the PL/SQL definition its type is NUMBER. Here is the Java code where it ...

29. Criteria API: query.from returns only null    stackoverflow.com

I'm pretty new to Criteria API, as a matter of fact I just pushed our latest project to JBoss 6 and JPA 2.0 just for the Criteria API. Now I am trying ...

30. Can't find entities in PersistenceContext after .persist()    stackoverflow.com

I am writing a JavaEE Project and am trying to get some unit tests on the way. The unit testing framework we use is JUnit, alongside Maven and Hudson for building ...

31. Is calling persist() flush() and refresh() in one method to persist an entity the right way?    stackoverflow.com

My intention is to return a newly persisted entity just in the same business call to a client in order to get the generated primary key needed for further business logic. ...

32. IntelliJ - Persistence QL Queries error-check over hibernate queries    stackoverflow.com

I have hibernate session query using a class recognized by hibernate. This query runs smoothly but is somehow recognized by IntelliJ IDEA as a Persistence QL Queries error - "Cant resolve ...

33. Force transitive persistence order in JPA 2 w/Hibernate?    stackoverflow.com

Is there any way to force the persistence order of objects in JPA 2 w/Hibernate? Say I have three classes: Parent, Child, and Desk. Parent owns collections of Child and Desk ...

34. error when trying to edit status of Order in admin interface(playframework)    stackoverflow.com

In my app ,I have a class Order that contains a collection of cartItems .The Order can have status 'pending' ,'confirmed' etc. After the customer placed the order,it has a status 'confirmed'.Since ...

35. Force Hibernate Insert Without Select Statements    stackoverflow.com

I am attempting to insert a new record into a table that I know is unique before hand. I have tried calling save() on the object, but that does a bunch ...

36. Why does the size of the persistence context affect query time in Hibernate    stackoverflow.com

for(int i = 0; i < 10000; i++) {
  Foo foo = dao.loadFooById(i);
}
//dao.getEntityManager().clear();
Bar bar = dao.loadBarById(0);
As it stands this code would take 200ms for the loadBarById(0) method. If I ...

37. javax.persistence.NoResultException: No entity found for query    stackoverflow.com

Before I posted this question, I already looked this , but I couldn't get what I was looking for. I know that for the query I wrote there may exist only ...

38. Can't get persistence to work in JBoss AS 7 ("Can't find a deployment unit named at subdeployment")    stackoverflow.com

I try to implement a demo that uses JBoss AS 7 with default hibernate and default Database shipped with JBoss AS. My implementation is similar to the "login" example from JBoss ...

39. OpenJPA 2.1.1 - Cannot find the declaration of element 'persistence'    stackoverflow.com

I just downloaded http://www.apache.org/dyn/closer.cgi/openejb/4.0.0-beta-1/apache-tomee-1.0.0-beta-1-webprofile.zip to use OpenEJB with OpenJPA2.1.1. I can't get my persistence.xml working. The top of the stack trace:

org.xml.sax.SAXException: file:/D:/Workspaces/sandbox/tomcat_ejb_jpa2_tomEE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/testEE/WEB-INF/classes/META-INF/persistence.xml [Location: Line: 2, C: 248]: ...

40. JPA: Can't find Persistence Provider    coderanch.com

Originally posted by Merrill Higginson: Thanks for your replies. I did try adding the stanza, but unfortunately, it didn't help. This problem appears to have something to do with the way applications are run inside Eclipse, because when I download the solution code and run it from an ANT task, it works fine.

43. Cannot have a jpa persistent object query inside a static init block    java.net

32 [httpWorkerThread-4848-0] ERROR User - User not found. javax.persistence.PersistenceException: Exception [TOPLINK-28019] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException Exception Description: deploy for PersistenceUnit [Spellscape] failed. Close all factories for this PersistenceUnit. Internal Exception: java.lang.NullPointerException at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:216) at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:93) at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:126) at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:99) at com.sun.enterprise.util.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:346) at com.sun.enterprise.util.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:660) at com.spellscape.main.RegisteredUser.get(RegisteredUser.java:51) at com.spellscape.main.Spellscape.init(Spellscape.java:32) [...]

45. Error in named queries while using Hibernate as Persistence    forum.hibernate.org

When i configured Hibernate as persitence provider in JPA using IBM RSA, and i try to test entities using JUnit , hibernate complains saying "error in Named queries". When i used Openjpa as persistence provider, i dont see any issues. Below is error log. javax.persistence.PersistenceException: Provider error. Provider: org.hibernate.ejb.HibernatePersistence at javax.persistence.Persistence.createFactory(Persistence.java:176) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:112) at mshp.fin.model.jpa.entity.manager.BaseManager.getEntityManager(BaseManager.java:19) at mshp.fin.model.jpa.util.EntityManagerUtil.getEntityManager(EntityManagerUtil.java:90) at mshp.fin.model.jpa.entity.controller.test.InvoiceBilledItemManagerTest.testCreateInvoiceBilledItem(InvoiceBilledItemManagerTest.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native ...

46. Externalise XML Queries with persistence annotations?    forum.hibernate.org

Hi all, I'm using Hibernate 3 annotations to persist the domain model. However I'd like to externalise Queries in a hibernate XML file. I'm using strict Hibernate (e.g. no JPA configuration with META-INF/persistence.xml). If you want to consider the following (I know we are in a Hibernate forum), I'm using Spring 2.5 to declare the SessionFactory as follows (but you may ...

47. Persisting a tree like structure    forum.hibernate.org

I have my beans class like : Code: public class Node { private int id ; private String name ; private Node parent ; private Setchildren ; // Getters and setters will come here } My hbm file is : Code: ...

49. Persistence Context For Queries    forum.hibernate.org

In Java Persistence With Hibernate book (2007 edition), on page 390, its mentioned that "The same is true if a query is executed through one of the Hibernate interfaces. Hibernate reads the result set of the query and marshals entity objects that are then returned to the application. During this process, Hibernate interacts with the current persistence context." However the above ...

50. Cascaded persist out of order on one-to-one relationship    forum.hibernate.org

I have an one-to-one, bidirectional entity relationship with shared keys. When I attempt to save the owner of the association I get a "null id generated" exception against the owned side of the relationship. I am utilizing hibernate-entitymanager and using spring for transaction management. Owning Entity Code: @Entity @Table(name = "lead") public class Lead { private Long leadId; ...

51. native queries with non-persisted values    forum.hibernate.org

52. Sort nested object collection in persisted object?    forum.hibernate.org

What is the best way (or is there a way at all) to sort a collection attached to a persisted object? I have a collection inside a persisted object mapped this way: Code: @OneToMany(mappedBy = "worksheetHeader", cascade=CascadeType.ALL) private List vehicles = new ArrayList(); I attempted to sort the contents in the getter before returning them: Code: ...

53. Cannot cast javax.persistence.Query to QueryImpl?    forum.hibernate.org

hey try this import org.hibernate.Query; private Transaction tx = null; private Session session = null; public Admin verifyLogin(String userId, String userPass) throws Exception { try { session = HibernateUtil.getSession(); tx = session.beginTransaction(); Query q = session.createQuery("from Admin where userId =:userId AND userPass = :userPass ); q.setString("userId", userId); q.setString("userPass", userPass); Admin result = (Admin) q.uniqueResult(); tx.commit(); return result; } catch (HibernateException e) ...

54. no persistent classes found for query class:    forum.hibernate.org

This is usually an easy fix, but this time it has me baffled. Hibernate 2.1.8. (Don't ask. I don't make the decisions here.) What's really baffling is it works in the JUnit tests, just not in my action class. And if I try to access other entities from our library in the same action, those DO work. It's only these new ...

55. NoClassDefFoundError: javax/persistence/criteria/Selection    forum.hibernate.org

Hi, I am using JPA 2.0 in my spring 3.0 project for the first time and get the following exception: java.lang.NoClassDefFoundError: javax/persistence/criteria/Selection at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) at java.lang.Class.getDeclaredConstructors(Class.java:1836) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:227) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:930) CriteriaBuilder queryBuilder = em.getCriteriaBuilder(); CriteriaQuery query = queryBuilder.createQuery(Order.class); Root root = query.from(Order.class); query.select(root); // When this line is removed I don't get the exception org.hibernate hibernate-entitymanager 3.5.1-Final ...

56. "no persistent classes found for query class": wha    forum.hibernate.org

this error typically means you have not configured your class. You should have something like: Code: Class[] classes = new Class[] { my.package.MyClass.class, ...

57. help needed- "no persistent classes found for query cla    forum.hibernate.org

Hello All , i generated the hbm files by using hib-middlegen, used the hbm2java to generate the java source files. wrote a java class to exercise hibernate using the hbm and the generated java files . However i keep getting this error : no persistent classes found for query class: from com.digitalthink.lms.fp.core.entity.hibernate.LmsCourse as o where o.COURSEID='100000' can anyone help me out ...

58. querying a tables with no persistent object?    forum.hibernate.org

Hi Guys! how can i do in hibernate to query a tables that don't have a corresponding persistent object? I had three tables contact, contact_industry and industry.the contact_industry is used for the relationship of contact and industry.I just created only two class Contact and Industry and the following is my mapping: ...

59. Error msg : No persistent classes found for query class    forum.hibernate.org

Hello, I inherited a project that uses Hibernate. I activated a function in the app that had not been used before and began getting the following error when the hibernate find function at runtime: no persistent classes for for query class. String query = "from mb in class com.company.project.beans.MyBean"+ " where mb.docId=? and mb.productId=?" Here is the Java code: MyBean mb ...

60. Can't find my persistent class and it is in the classpath!    forum.hibernate.org

Hi All, I am trying to run SchemaExport thru ant in Eclipse and I keep getting an error message. I know I must be doing something wrong, but I cannot figure it out. Please help. Thanks in advance, Kevin Here is the error message: Buildfile: D:\eclipse\workspace\VAM2\build.xml schemaexport: [echo] SchemaExport Classpath: D:\eclipse\workspace\VAM2\build\WEB-INF\classes [echo] Does class exist? true [schemaexport] BUILD FAILED: file:D:/eclipse/workspace/VAM2/build.xml:540: Schema ...

62. query design problem/identifying a persistent record    forum.hibernate.org

I am refurbishing an existing utility which imports university candidate and school data from files into a database. It must be able to receive data regarding a given applicant on separate occasions and be able to update the persistent record with the latest state as represented by the file record. For many record types the primary keys are generated by the ...

63. order persistence collections    forum.hibernate.org

I have a user which have many items. So user have a collection: user.getItems(); and i want to order items owned by user at runtime. How to modify this collection? filter are not good for that : session.filter(user.getItems(), "...").list(); return another collection instead of change the user property in place. How to achieve that?

64. Prevent Flushing from Queries - Explicit to Session.persist    forum.hibernate.org

Nevermind, it was a problem with my MoneyUserType and deepCopy, so every flush was saying the Order Total was dirty (a Money object). But, is the expected behavior that if an object is fetched in a read only query, that all other pointers to that object can never be modified? * Object A is returned in a Read-Only Query. * In ...

65. Query cache isn't persisting across instances    forum.hibernate.org

Hi all, First things first, we're using JDK 1.5.0_01, Oracle 9i and Hibernate 3.0.3. We've got Hibernate configured to use 3 databases (i.e. 3 hibernate.XXX.cfg.xml) files. We're getting some odd behaviour with caching queries to 2 out of the 3 databases. The first one works fine but when querying the other 2 the query cache is used while in memory but ...

66. changing persistent object id w/o query?    forum.hibernate.org

67. Evaluating Hibernate: Can I use query without persistence?+    forum.hibernate.org

I'm evaluating Hibernate for use in an already existing application. We're using JB2005, BES 6.5 (Borland's EJB/J2EE Container), and using CMP with some persistence code that is code generated by a JB integrated 3rd party tool. We pretty much have Transfer Objects that correspond 1:1 with db rows. Currently, we need some multi-table advanced search type functionality, and are evaluating search ...

68. How do you persist set defined with where clause    forum.hibernate.org

Thanks anar, that's waht I needed. Code: ...

69. javax.persistence.NamedQuery annotation and query cache    forum.hibernate.org

Hibernate version: 3.1 beta 1 Hi all, I'm mapping entities with the new annotation classes, using javax.persistence ones (when possible). In order to activate the cache on the entities, I'm using the hibernate "@Cache" annotation, but, when looking at the query cache, I cannot mark a query as "cacheable", because there is no hibernate "NamedQuery" annotation extending the javax.persistence one and ...

70. no persistent classes found for query class    forum.hibernate.org

Newbie Joined: Thu Sep 15, 2005 12:36 pm Posts: 4 This is my first time working with hibernate, I am following a couple of tutorials and I am just trying to get one object working. Everything seems to start up and deploy ok in JBoss, but when I run a servlet to test I get: "[QuerySplitter] no persistent classes found for ...

71. Order of Persistent problem    forum.hibernate.org

72. Querying table and column names from persistent objects    forum.hibernate.org

For some reason the getCollectionMapping(String) operation is returning null for a class name that I know exists in the Hibernate mappings and that I am actively using in my Java program. What would cause this operation to return null instead of the Collection? String className = MyTestObject.getClass().getName(); // Given Configuration configuration has already be initialized. Collection collectoin = configuration.getCollectionMapping(className);

73. Persistence order of OneToOne foreign key-based relationship    forum.hibernate.org

Hibernate version: 3.1, annotations 3.1 beta 7 Hi I am modelling a legacy Oracle 9 database using Hibernate 3.1 with annotations (3.1 beta 7) and I have come across an interesting problem. I have two tables linked by a foreign key. Here's a simplified diagram: Code: +------------------------+ | MESSAGE ...

74. No persistent classes found for query class    forum.hibernate.org

75. [DEJA VU] no persistent classes found for query class    forum.hibernate.org

Author Message filou Post subject: [DEJA VU] no persistent classes found for query class Posted: Wed Mar 15, 2006 6:39 am Newbie Joined: Mon Mar 13, 2006 12:03 pm Posts: 6 Hibernate version: Hibernate 3.1.2 / annotations 3.1beta8 / JDK 5.0 / Eclipse 3.1.1 / Win2000 hibernate.cfg.xml: Code:

76. [QuerySplitter] no persistent classes found for query class:    forum.hibernate.org

I have been facing this problem since long time. I have created an Enterprise Application using Struts, EJB(Session) and Hibernate. I m trying to fire a simple SELECT query using Hibernate. When i run the query in standalone class i am able to retrive the resultset. However when I use the same in the EAR project it gives me a WARN[QuerySplitter] ...

77. EntityManger.find() not finding persisted Entity (postgres)    forum.hibernate.org

Senior Joined: Tue Jul 25, 2006 9:05 am Posts: 163 Location: Stuttgart/Karlsruhe, Germany Hibernate version: 3 (version that ships with JBoss 4.0.4GA) Name and version of the database you are using: PostgreSQL 8.1.4 We currently have an JBoss application that receives a byte stream and persists it wit hibernate and then reads it from the db for further parsing before saving ...

78. no persistent class for query    forum.hibernate.org

79. Persisting on criteria query    forum.hibernate.org

Author Message samblake Post subject: Persisting on criteria query Posted: Mon Apr 02, 2007 12:55 pm Newbie Joined: Mon Apr 02, 2007 12:53 pm Posts: 5 Hi, I am inside a EJB2 transaction part way through creating an object to persist. I have an object which has among other things an ID and a code. I want to look ...

80. em.persist(Order) does not work    forum.hibernate.org

Hi, I try to implement an order in a webshop. Therefore i have an relation Orders, an relation orderpositions and an relation article. The table orderpositions has the columns: artnr(Foreign key. PK in article), ordnr(Foreign key. PK in Orders), posnr(Primary key) and quantity. The ordnr is an autogenerated value(in Orders). When I try to persist an Order (entitymanager.persist(order)), hibernate should persist ...

82. javax.persistence.EntityNotFoundException: Unable to find...    forum.hibernate.org

When I do a search to use criteria, this happens exception. The Code of the criteria is this: PersistenceFacade.getSession Session session = (); List result = session.createCriteria (ConvenioTlfHistorico.class) . SetMaxResults (10) . List (); System.out.println (result.size ()); It turns out that this error should not be because I put the annotation @NotFound (action = NotFoundAction.IGNORE) What is happening? Hibernate version: 3 ...

83. Ordering saves when using transitive persistence    forum.hibernate.org

/** * The contacts for this organization */ @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "organization") @org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN) private Set contacts = new HashSet(); /** * The ...

85. how to persist an object which is getting refreshed    forum.hibernate.org

Hi, I am trying to save an object Item which has a price to it. Class Item{ Price price; } Now, Price is an object in itself and its value changes very frequently. So at any point of time, when I am ordering any Item it should take the price at that instance of time and save it in price table. ...