jpa-2.0

Silently ignored remove()

匆匆过客 提交于 2019-11-26 23:16:56
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 where I came to conclusion that orphanRemoval not always works as expected. Now I am starting to suspect that

getting error No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined: expected single matching bean but found 2

拈花ヽ惹草 提交于 2019-11-26 23:13:33
问题 I am spring spring 3.2. Here is my config file <bean id="legacyDataSource" name="legacydb" class="org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init="true"> <property name="driverClassName" value="${jdbc.legacy.driverClassName}" /> <property name="url" value="${jdbc.legacy.url}" /> <property name="username" value="${jdbc.legacy.username}" /> <property name="password" value="${jdbc.legacy.password}" /> </bean> <bean id="ls360DataSource" name="Ls360db" class="org

JPA - Criteria API and EmbeddedId

耗尽温柔 提交于 2019-11-26 23:01:00
问题 I want to use criteria to make the following query. I have an Entity with EmbeddedId defined: @Entity @Table(name="TB_INTERFASES") public class Interfase implements Serializable { @EmbeddedId private InterfaseId id; } @Embeddable public class InterfaseId implements Serializable { @Column(name="CLASE") private String clase; } And the criteria query that i am trying to do is: CriteriaBuilder criteriaBuilder = this.entityManager.getCriteriaBuilder(); CriteriaQuery<Interfase> criteriaQuery =

java.lang.IllegalStateException: Multiple representations of the same entity with @ManyToMany 3 entities

情到浓时终转凉″ 提交于 2019-11-26 22:39:16
I have 3 entities with ManyToMany relationships: Role Entity: @Entity public class Role { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer roleID; private String roleName; private String description; @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER) @JoinTable(name = "role_permission", joinColumns = {@JoinColumn(name = "role_id")}, inverseJoinColumns = {@JoinColumn(name = "permission_id")}) private Set<Permission> permissions = new LinkedHashSet<Permission>(); } Permission Entity: @Entity public class Permission

JPA Criteria Tutorial [closed]

断了今生、忘了曾经 提交于 2019-11-26 22:19:43
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I've been trying to find a JPA Criteria API tutorial but haven't been much successful. Do you know about any for beginners? I'd like to start using it in an Java5/Maven app to build complex search queries. 回答1: The Dynamic, typesafe queries in JPA 2.0 article is a very good one on this topic, actually the best

How to properly cast string to number with JPA2 Criteria API?

放肆的年华 提交于 2019-11-26 22:08:24
问题 I am trying to write a query with subselect where a string is cast to a long. I'm probably missing something? Query looks like: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Task> query = cb.createQuery(Task.class); Root<Task> from = query.from(Task.class); Subquery<Long> subquery = query.subquery(Long.class); Root<EntityKeyword> fromKeyword = subquery.from(EntityKeyword.class); subquery.select(fromKeyword.get(EntityKeyword_.relatedToId).as(Long.class)); subquery.where(cb.like

Upgrading GlassFish 3.1.2.2 to use JPA 2.1

老子叫甜甜 提交于 2019-11-26 22:02:33
问题 I am working with GlassFish 3.1.2.2 (I can not upgrade to 4 due to OS restrictions). I'm interested in upgrading JPA 2.0 to JPA 2.1 GlassFish 3.1.2.2. How can I achieve this? 回答1: This is most likely not possible at all. JPA 2.1 is part of EE 7 and therefore not fully integrated with EE 6 GF 3.1.2.2. 回答2: Did you try just replacing the EclipseLink and JPA jar files in Glassfish? It will probably work, but if you use managed persistence units they will not expose any JPA 2.1 API, you would

Generate JPA 2 Entities from existing Database

匆匆过客 提交于 2019-11-26 21:56:07
How can I generate JPA2 compliant @Entity from existing Databases?. I found this: Question Still its not clear if JBoss will generate compliant JPA2 and also I would like to know if there is a vendor independent way to do this. You can use a plugin like Eclipse Dali to do the trick for you. You can refer to the documentation, section 3.11 Generating Entities from Tables . I do not know of any specific vendor independent tool to do this, though. Try using OPENJPA Reverse mapping tools. They offer lot more facility and are easy to configure. This example would clarify. If you are using maven as

Why do the JPA2 MetaModel get generated with volatile members?

感情迁移 提交于 2019-11-26 21:39:26
问题 I have just used org.apache.openjpa.persistence.meta.AnnotationProcessor6 to generate the MetaModel for my JPA2 entities. @javax.annotation.Generated (value="org.apache.openjpa.persistence.meta.AnnotationProcessor6", date="Tue Nov 22 09:49:03 CET 2011") public class Entity_ { public static volatile SingularAttribute<Entity,Entity> id; public static volatile SingularAttribute<Entity,String> value; public static volatile SingularAttribute<Entity,String> order; } Can someone please explain why

How to countDistinct on multiple columns

ⅰ亾dé卋堺 提交于 2019-11-26 21:22:02
问题 How can I, using the JPA criteria API do the following: select count(distinct column1, column2) from table Doing this on one column/path is simple using CriteriaBuilder.countDistinct, but how can I do this on two paths/columns? 回答1: Here is a late answer :-) though I'm not sure if things had changed. Recently I encountered the very same need, and worked around it using concat, i.e., by concatenating the columns into a pseudo column , then countDistinct on the pseudo column. But I couldn't use