jpa-2.0

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

为君一笑 提交于 2019-11-26 12:20:10
问题 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)

Hibernate generates negative id values when using a sequence

拜拜、爱过 提交于 2019-11-26 12:06:38
问题 I have a class with the following definition: @Id @SequenceGenerator(name = \"SEQ_ACE_WORKERS_QUEUE_STATS_ID\", sequenceName = \"SEQ_ACE_WORKERS_QUEUE_STATS_ID\", allocationSize = 500) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = \"SEQ_ACE_WORKERS_QUEUE_STATS_ID\") @Column(name = \"ID\") private long Id; When we ran it on Jboss 4.2.3 it worked fine and generated the proper ID\'s (starting from 1000+) Now we moved to jboss 7.1.1 and it generates negative ID\'s! (starting

How to generate JPA 2.0 metamodel?

一个人想着一个人 提交于 2019-11-26 12:04:21
In the spirit of type safety associated with the CriteriaQuery JPA 2.0 also has an API to support Metamodel representation of entities. Is anyone aware of a fully functional implementation of this API (to generate the Metamodel as opposed to creating the metamodel classes manually)? It would be awesome if someone also knows the steps for setting this up in Eclipse (I assume it's as simple as setting up an annotation processor, but you never know). EDIT: Just stumbled across Hibernate JPA 2 Metamodel Generator . But the issue remains since I can't find any download links for the jar. EDIT 2:

Really dynamic JPA CriteriaBuilder

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 11:53:12
问题 I need to create a \"real\" dynamic JPA CriteriaBuilder . I get an Map<String, String> with the statements. It looks like: name : John surname : Smith email : email@email.de ...more pairs possible Here is what i implement: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> userRoot = query.from(User.class); query.select(userRoot); List<Predicate> predicates = new ArrayList<Predicate>(); Iterator<String> column = statements.keySet()

Java EE Architecture - Are DAO&#39;s still recommended when using an ORM like JPA 2?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 11:51:58
问题 If I\'m using an ORM like JPA2 - where I have my entities that are mapped to my database, should I still be using a DAO? It seems like a lot more overhead. For example, I would need to maintain three extra packages: One that specifies my domain objects (which pretty much map my Entity objects): public class Employee { private String firstName; private String lastName; ... // Getters and setters } One that contains interfaces that specify my DAO methods public interface EmployeeDAO { public

Confusion: @NotNull vs @Column(nullable = false)

让人想犯罪 __ 提交于 2019-11-26 11:34:42
When they appear on a field/getter of an @Entity , what is the difference between them? (I persist the Entity through Hibernate ). What framework and/or specification each one of them belongs to? @NotNull is located within javax.validation.constraints . In the javax.validation.constraints.NotNull javadoc it says The annotated element must not be null but it does not speak of the element's representation in the database, so why would I add the constraint nullable=false to the column? Ryan Stewart @NotNull is a JSR 303 Bean Validation annotation. It has nothing to do with database constraints

Storing a Map<String,String> using JPA

六月ゝ 毕业季﹏ 提交于 2019-11-26 10:15:23
I am wondering if it is possible using annotations to persist the attributes map in the following class using JPA2 public class Example { long id; // .... Map<String, String> attributes = new HashMap<String, String>(); // .... } As we already have a pre existing production database, so ideally the values of attributes could map to the following existing table: create table example_attributes { example_id bigint, name varchar(100), value varchar(100)); JPA 2.0 supports collections of primitives through the @ElementCollection annotation that you can use in conjunction with the support of java

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

这一生的挚爱 提交于 2019-11-26 09:57:47
问题 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

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

时光毁灭记忆、已成空白 提交于 2019-11-26 09:26:56
问题 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

Silently ignored remove()

喜夏-厌秋 提交于 2019-11-26 09:14:30
问题 There is entity A referring (many-to-one) entity B, with inverse (mapped-by) reference from B to A. Also there is reference A to C and inverse reference C to A. When I issue entityManager.remove(A) then flush(), \"delete\" is not gerenated! But also there are no exceptions. It\'s just like no remove() was called at all. Why would that happen? If before remove() we extract A from reverse references B.listOfA and C.listOfA, \"delete\" is generated as expected. Also note my another question