jpa-2.0

JPA 2.0 orphanRemoval=true VS on delete Cascade

六月ゝ 毕业季﹏ 提交于 2019-11-26 04:04:19
问题 I am a little confused about the JPA 2.0 orphanRemoval attribute. I think I can see its is needed when I use my JPA provider\'s DB generation tools to create the underlying database DDL to have an ON DELETE CASCADE on the particular relation. However, if the DB exists and it already has an ON DELETE CASCADE on the relation, is this not enough to cascade the deletion appropriately? What does the orphanRemoval do in addition? Cheers 回答1: orphanRemoval has nothing to do with ON DELETE CASCADE .

JPA CascadeType.ALL does not delete orphans

左心房为你撑大大i 提交于 2019-11-26 03:11:34
I am having trouble deleting orphan nodes using JPA with the following mapping @OneToMany (cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "owner") private List<Bikes> bikes; I am having the issue of the orphaned roles hanging around the database. I can use the annotation org.hibernate.annotations.Cascade Hibernate specific tag but obviously I don't want to tie my solution into a Hibernate implementation. EDIT : It seems JPA 2.0 will include support for this. Varun Mehta If you are using it with Hibernate, you'll have to explicitly define the annotation CascadeType.DELETE_ORPHAN

How to generate JPA 2.0 metamodel?

好久不见. 提交于 2019-11-26 02:50:27
问题 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

How can I validate two or more fields in combination?

邮差的信 提交于 2019-11-26 02:49:53
问题 I\'m using JPA 2.0/Hibernate validation to validate my models. I now have a situation where the combination of two fields has to be validated: public class MyModel { public Integer getValue1() { //... } public String getValue2() { //... } } The model is invalid if both getValue1() and getValue2() are null and valid otherwise. How can I perform this kind of validation with JPA 2.0/Hibernate? With a simple @NotNull annotation both getters must be non-null to pass validation. 回答1: For multiple

Storing a Map<String,String> using JPA

自古美人都是妖i 提交于 2019-11-26 02:29:02
问题 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)); 回答1: JPA 2.0 supports collections of

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

妖精的绣舞 提交于 2019-11-26 02:28:03
问题 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? 回答1:

JPA CascadeType.ALL does not delete orphans

China☆狼群 提交于 2019-11-26 01:13:04
问题 I am having trouble deleting orphan nodes using JPA with the following mapping @OneToMany (cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = \"owner\") private List<Bikes> bikes; I am having the issue of the orphaned roles hanging around the database. I can use the annotation org.hibernate.annotations.Cascade Hibernate specific tag but obviously I don\'t want to tie my solution into a Hibernate implementation. EDIT : It seems JPA 2.0 will include support for this. 回答1: If you are

JPA 2.0, Criteria API, Subqueries, In Expressions

那年仲夏 提交于 2019-11-26 00:59:05
问题 I have tried to write a query statement with a subquery and an IN expression for many times. But I have never succeeded. I always get the exception, \" Syntax error near keyword \'IN\' \", the query statement was build like this, SELECT t0.ID, t0.NAME FROM EMPLOYEE t0 WHERE IN (SELECT ? FROM PROJECT t2, EMPLOYEE t1 WHERE ((t2.NAME = ?) AND (t1.ID = t2.project))) I know the word before \'IN\' lose. Have you ever written such a query? Any suggestion? 回答1: Below is the pseudo-code for using sub

JPA 2.0, Criteria API, Subqueries, In Expressions

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-25 21:34:57
I have tried to write a query statement with a subquery and an IN expression for many times. But I have never succeeded. I always get the exception, " Syntax error near keyword 'IN' ", the query statement was build like this, SELECT t0.ID, t0.NAME FROM EMPLOYEE t0 WHERE IN (SELECT ? FROM PROJECT t2, EMPLOYEE t1 WHERE ((t2.NAME = ?) AND (t1.ID = t2.project))) I know the word before 'IN' lose. Have you ever written such a query? Any suggestion? Below is the pseudo-code for using sub-query using Criteria API. CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery