jpa-2.0

How to add persisted entities in a relationship marked with CascadeType.ALL?

做~自己de王妃 提交于 2019-12-13 19:26:09
问题 I have an Entity with a bidirectional ManyToMany relationship (on the same entity) marked as CascadeType.ALL . Here is how it looks for the Contact entity: @ManyToMany(cascade= CascadeType.ALL) private List<Contact> parentContacts = new ArrayList<Contact>(); @ManyToMany(cascade= CascadeType.ALL, mappedBy="parentContacts") private List<Contact> childContacts = new ArrayList<Contact>(); I have a method on the server side supposed to do save this entity: public AltContact saveContact

OneToMany, ManyToOne why value of parent in children is null?

笑着哭i 提交于 2019-12-13 17:54:05
问题 I read similar questions, but still have problem. Configuration info: Hibernate 3.5.1 Parent class Question: @Entity public class Question implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="questionId") private long id; private String title; private String description; @OneToMany(cascade=CascadeType.ALL, mappedBy="question") private Set<Vote> votes; public void addVote(Vote vote){ if(votes==null)

Is there any JPAv2-compatible vendor agnostic persistence api public available

蹲街弑〆低调 提交于 2019-12-13 17:34:33
问题 The JPA 2 maven packages I've met so far was only complete realizations either from hibernate or eclipse. But I want to build my package agains vendor agnostic api. Is it available public? 回答1: The JPA spec group were too lazy to bother releasing a vendor neutral API jar for JPA 2.0 and JPA 2.1. See for example https://java.net/jira/browse/JPA_SPEC-60 You simply have to pick a vendor's own one and hope they didn't put vendor-specifics in there. Naff 回答2: Take a look at org.hibernate.javax

Suqueries in select clause with JPA

白昼怎懂夜的黑 提交于 2019-12-13 15:22:58
问题 I need to execute a subquery in a select clause with Apache Openjpa 2. Does JPA support subqueries in SELECT clause? My Query is something like this: SELECT t.date, t.value, (SELECT COUNT(DISTINCT t2.value2) FROM table t2 WHERE t2.date = t.date) FROM table t WHERE ... When I execute my query, I get a class cast exception: Exception in thread "main" <openjpa-2.1.1-SNAPSHOT-r422266:1141200 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: at org.apache.openjpa.kernel

Create (querydsl) metamodel for Entity from jar

。_饼干妹妹 提交于 2019-12-13 14:59:12
问题 I'm having problems generating the querydsl metamodel (i.e. the Q-classes) for an Entity comming from a jar included in the dependencies for my project. The class (BaseEntity) is an abstract baseclass for most of my entities (annotated with @MappedSuperclass) and for project reasons and dependencies to other projects this baseclass has to be in a separate jar. When I now include this jar as a dependency for the project which contains my non-abstract entities and try to generate the metamodel

Does the JPQL avg aggregate function work with Integers?

泄露秘密 提交于 2019-12-13 13:11:27
问题 I have a JPA 2 Entity named Surgery . It has a member named transfusionUnits that is an Integer . There are two entries in the database. Executing this JPQL statement: Select s.transfusionUnits from Surgery s produces the expected result: 2 3 The following statement produces the expected answer of 5 : Select sum(s.transfusionUnits) from Surgery s I expect the answer of the following statement to be 2.5 , but it returns 2.0 instead. Select avg(s.transfusionUnits) from Surgery s If I execute

Injecting JPA's Entity Manager in Hibernate's EmptyInterceptor

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 11:42:19
问题 I am using JPA-2.0 with Hibernate in my data access layer. For audit logging purposes, I am using Hibernate's EmptyInterceptor by configuring below property in persistence.xml: <property name="hibernate.ejb.interceptor" value="com.mycom.audit.AuditLogInterceptor" /> Where AuditLogInterceptor extends hibernate's ' org.hibernate.EmptyInterceptor '. public class AuditLogInterceptor extends EmptyInterceptor { private Long userId; public AuditLogInterceptor() {} @Override public boolean onSave

How to stop hibernate to do select before insert in child table in @ManyToOne mapping?

Deadly 提交于 2019-12-13 07:58:55
问题 How to stop hibernate to do select before insert in child table in many to one mapping? I have a student table : @Entity @Table @NoArgsConstructor @AllArgsConstructor @Builder @Data @IdClass(StudentId.class) public class Student implements Persistable<StudentId> { @Id private String studentUuid; @Id private String studentName; @Column private String sex; public Student(String studentUuid,String studentName){ this.studentUuid = studentUuid; this.studentName = studentName; } @ManyToOne(fetch =

Hibernate column refer the total of details

大憨熊 提交于 2019-12-13 07:46:40
问题 I have a table order and a table order_items (one order has many order_items ). I want to have a column in order entity that refers to the sum of the column values in order items. is there a way to do it in Hibernate? At each update or insert of related order items, I want to recalculate the value in order table. For example: Order a: has 3 records in order_items with value 1, 2, 3. The column total on order must be 6. 回答1: This should be possible with the @Formula annotation and a subselect

JPA Composite Key with Object references

孤街浪徒 提交于 2019-12-13 07:33:49
问题 I have faced some issue while creating JPA Composite Key with Object references. Entities are as show in bellow, 1) I wan to remove the ID field from Workflow entity and make a composite key with combining seqNo field and template (object reference) field 2) According to that change updated the existing relationship with Command entity (@JoinColumn(name = "WORKFLOW_ID", referencedColumnName = "ID")) Thanks. Template entity: @Entity @Table(name = "template") public class Template implements