jpa-2.0

Dynamic JPA 2.0 query using Criteria API

依然范特西╮ 提交于 2019-12-18 15:34:19
问题 I am a bit stucked constructing a dynamic query using the CriteriaBuilder of JPA 2.0. I have quite a common use case I guess: User supplies a arbitrary amount of search parameters X to be and / or concatenated: like : select e from Foo where (name = X1 or name = X2 .. or name = Xn ) The Method or of CriteriaBuilder is not dynamic: Predicate or(Predicate... restrictions) Ideas? Samples? 回答1: In your case, I would rather use Expression#in(Collection) to avoid having to loop and to build a

@PersistenceContext EntityManager thread-safety in Spring and Java EE

纵然是瞬间 提交于 2019-12-18 15:33:46
问题 EntityManager is not thread-safe by definition. Servlets specs says that in non-distributed environment and without implementing SingleThreadModel , there is only one servlet instance per definition . Therefore, in Java EE when you inject an EntityManager through the @PersistenceContext into Servlet's field - it's not thread safe: public class MyServlet extends HttpServlet { // Not thread-safe, should be using EMF instead. @PersistenceContext private EntityManager em; } Is this correct to say

Execute sql script after jpa/EclipseLink created tables?

烂漫一生 提交于 2019-12-18 15:07:15
问题 is there a possibility to execute an sql script, after EclipseLink generated the ddl? In other words, is it possible that the EclipseLink property "eclipselink.ddl-generation" with "drop-and-create-tables" is used and EclipseLink executes another sql-file (to insert some data into some tables just created) after creating the table definition? I'm using EclipseLink 2.x and JPA 2.0 with GlassFish v3. Or can I init the tables within a java method which is called on the project (war with ejb3)

Multiple @MappedSuperclass

别等时光非礼了梦想. 提交于 2019-12-18 14:54:16
问题 I'm using JPA 2.0 and EclipseLink 2.2.0. I have a @MappedSuperclass, AbstractEntity, that is the basis for all my entities providing PK and auditing columns. I want to have another @MappedSuperclass extend that class and be the root for a TABLE_PER_CLASS inheritance strategy. At present, when building with Maven I receive header errors. Are multiple @MappedSuperclass allowed in an inheritance hierarchy? 回答1: Multiple mapped superclasses are allowed in same inheritance hierarchy. It is not

Correct usage of JPA criteria API, Predicates and where method of CriteriaQuery

▼魔方 西西 提交于 2019-12-18 11:35:38
问题 I am trying to test a JPA repository. Here is my client/test code: @Test public void testFindBoitesByMultiFieldWithIdentifiantSet() { BoiteDataOnDemand dod = new BoiteDataOnDemand(); Boite boite = dod.getSpecificBoite(0); boite.setIdentifiant("theIdentifiant"); boiteRepository.save(boite); assertEquals(10, Boite.countBoites()); BoiteQueryInfo boiteQueryInfo = new BoiteQueryInfo(); boiteQueryInfo.setIdentifiant("theIdentifiant"); List<Boite> boites = boiteRepository.findBoitesByMultiField

How JPA transactions works

末鹿安然 提交于 2019-12-18 11:35:19
问题 Following code gets executed whenever I want to persist any entity. Things seems to be working fine but I fail to understand how it works ! EntityManager em = getEntityManager(); EntityTransaction userTransaction = em.getTransaction(); userTransaction.begin(); em.persist( ent ); userTransaction.commit(); The EntityManager above is a single instance shared by whole application. After starting the transaction; I just say em.persist(entity).. How does hibernate know it belongs to which

org.hibernate.QueryException: illegal attempt to dereference collection

淺唱寂寞╮ 提交于 2019-12-18 10:37:54
问题 I am trying following hql query to execute SELECT count(*) FROM BillDetails as bd WHERE bd.billProductSet.product.id = 1002 AND bd.client.id = 1 But it is showing org.hibernate.QueryException: illegal attempt to dereference collection [billdetail0_.bill_no.billProductSet] with element property reference [product] [select count(*) from iland.hbm.BillDetails as bd where bd.billProductSet.product.id=1001 and bd.client.id=1] at org.hibernate.hql.ast.tree.DotNode$1

Which Java Type do you use for JPA collections and why?

南笙酒味 提交于 2019-12-18 10:11:41
问题 Which of the following collection types do you use in your JPA domain model and why: java.util.Collection java.util.List java.util.Set I was wondering whether there are some ground rules for this. UPDATE I know the difference between a Set and a List . A List allows duplicates and has an order and a Set cannot contain duplicate elements and does not define order. I'm asking this question in the context of JPA. If you strictly follow the definition, then you should always end up using the Set

JPA Hibernate many-to-many cascading

北城以北 提交于 2019-12-18 10:01:45
问题 I am using JPA 2.0 and hibernate. I have a User class and a Group class as follows: public class User implements Serializable { @Id @Column(name="USER_ID") private String userId; @ManyToMany @JoinTable(name = "USER_GROUP", joinColumns = { @JoinColumn(name = "GROUP_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") } ) private Set<Group> groupList; //get set methods } public class Group { @Id @Column(name="GROUP_ID") private String groupId; @ManyToMany(mappedBy="groupList") private

Does JPA 2.0 support SQL Server table variables?

你说的曾经没有我的故事 提交于 2019-12-18 05:21:39
问题 I am using JPA 2.0 and SQL Server 2008 and I have determined that JPA doesn't like my stored procedures when I use a table variable. For example, this sproc works: declare @t table ( id int identity , test varchar(50) ) select 'blah' as test -- I'm ignoring the table variable above However, when I try to insert something into the table variable @t with this code, it crashes: declare @t table ( id int identity , test varchar(50) ) insert into @t select cast(getdate() as varchar(60)) select *