jpa-2.0

FetchMode in JPA 2 CriteriaQuery

别来无恙 提交于 2019-11-27 02:44:21
问题 I'm currently in the process of switching from Hibernate to pure JPA 2 (which by the way turned out to be much more time consuming than I initially expected). The biggest problem I'm having so far is finding a way to force eager loading of lazy properties. With Hibernate this was done using: criteria.setFetchMode("person", FetchMode.JOIN); . Is there any way to do this with JPA 2? 回答1: Try this: CriteriaQuery<Person> c = cb.createQuery(Person.class); Root<Person> person = c.from(Person.class)

Exception in GWT Dev Mode + Spring 3.1 + Hibernate 4.0.1

本小妞迷上赌 提交于 2019-11-27 02:26:43
问题 I have a GWT+Hibernate+JPA+Spring configuration file which is OK with Spring 3.0.x + Hibernate 3.6.x. When I upgraded to Spring 3.1 and Hibernate 4.0, the following exception is thrown: Is there any known incompatibility withe Hibernate 4 and Spring 3.1? org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/application-context.xml]: Invocation of init method failed; nested exception is javax

JPQL Constructor Expression - org.hibernate.hql.ast.QuerySyntaxException:Table is not mapped

╄→гoц情女王★ 提交于 2019-11-27 02:07:09
My original problem was https://stackoverflow.com/questions/12172614/hql-join-without-foreign-key-reference but couldn't find any solution for this, hence moved forward with native query using JPA. createNativeQuery of entityManager returns Query object which in turn returns List<Object[]> . I don't want to deal with indexes while iterating the list because it's error prone in nature.Therefore i looked at some other solution for it and found JPQL's Constructor expressions as one of the solution. Table structure is Schema1 -TableA - NameColumn - PhoneColumn Corresponding Java class is public

JPA 2.0 : Exception to use javax.validation.* package in JPA 2.0

 ̄綄美尐妖づ 提交于 2019-11-27 01:40:20
when i try to using bean validation with JPA using hibernate , the follwoing exception will occur : Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: Chapter11] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)

How to configure JPA 2.0 with Hibernate 3.5.2 to use EHCache as a Level 2 cache and query cache?

做~自己de王妃 提交于 2019-11-27 01:01:58
问题 I found some instructions how to configure pure hibernate to use EHCache. But I can't find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5.2 is my JPA2.0 provider. edit// Is @Cacheable(true) enough for entity? Or should I use @org.hibernate.annotations.Cache to configure the entity? 回答1: I found some instructions how to configure pure hibernate to use EHCache. But I can't find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5

What is the difference between @Inject and @EJB

痴心易碎 提交于 2019-11-27 00:57:35
问题 I'm currently learning the new Java EE 6 component models and am confused with the latest dependency injection mechanism. So here are my questions: 1) What is the difference between @Inject and @EJB 2) If I have a simple POJO that contains another POJOs (which one of them is the DAO code), what would be the better choice: @Inject or @EJB? Can I mix @Inject and @EJB? An example would be: ClassA implements InterfaceA and has an instance of ClassA_Adaptor ClassA_Adaptor implements InterfaceAB

Criteria JPA 2 with 3 tables

廉价感情. 提交于 2019-11-27 00:45:08
问题 I'm trying to create a criteria to retrieve some objects from 3 tables (Associate, Update and Detail). A Detail has reference to Associate and Update, and an Update has reference to a list of Details. My objective is to retrieve a list of Updates that has at least a Detail with null value in a specified field, given an Associate id. In JPQL was easy to do but the client said that this must be coded with criteria. My JPQL was: public List<Update> getUpdates(long associateId) { TypedQuery

JPA 2.0: Adding entity classes to PersistenceUnit *from different jar* automatically

浪尽此生 提交于 2019-11-27 00:41:49
I have a maven-built CDI-based Java SE app, which has a core module, and other modules. Core has the persistence.xml and some entities. Modules have additional entities. How can I add the entities to the spotlight of the persistence unit? I have read Hibernate manual, http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/configuration.html#setup-configuration-packaging I have also seen these SO questions How can I merge / extend persistence units from different JARs? define jpa entity classes outside of persistence.xml Programmatically loading Entity classes with JPA 2.0? I am

How to retrieve the datasource used by a persistence unit programmatically

旧街凉风 提交于 2019-11-27 00:37:44
问题 ...without actually reading and parsing the persistence.xml I can retrieve the name of the persistence unit of an EntityManager using the properties of it's factory. I can retrieve the available datasources using the jboss-as-controller-client. But I have found no API that would give me the datasource of a particular EntityManager . A String with a name would be enough. Thank you I am working with Hibernate 4.0.1.Final over JPA 2 on a JBoss 7.1.1.Final. EDIT: and I would like to avoid

In JPA 2, using a CriteriaQuery, how to count results

ぃ、小莉子 提交于 2019-11-26 23:33:56
I am rather new to JPA 2 and it's CriteriaBuilder / CriteriaQuery API: CriteriaQuery javadoc CriteriaQuery in the Java EE 6 tutorial I would like to count the results of a CriteriaQuery without actually retrieving them. Is that possible, I did not find any such method, the only way would be to do this: CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<MyEntity> cq = cb .createQuery(MyEntityclass); // initialize predicates here return entityManager.createQuery(cq).getResultList().size(); And that can't be the proper way to do it... Is there a solution? Affe A query of type