jpa-2.0

2nd level cache invalidation with native queries

南笙酒味 提交于 2019-12-04 05:20:20
问题 I have an application that uses 2nd level cache on a JBoss AS 7 installation (Infinispan 2nd level cache provider). We have some update JPQL Queries that invalidate the cache- I wonder what will be the effect if we include some native SQL queries in our application. Will the Query cache be invalidated ? Also I remember using the sqlQuery.addSynchronizedQuerySpace("") instruction on Hibernate to prevent cache invalidation for some native SQL queries. Is it possible to do it also with JPA ?

how to disable cache in eclipselink

泄露秘密 提交于 2019-12-04 05:00:39
问题 I have tried disabling L2 cache in EclipseLink with Eclipse indigo by using following properties in persistence.xml:- <property name="eclipselink.cache.shared.default" value="false"/> <shared-cache-mode>NONE</shared-cache-mode> Basically I am testing one scenario whether same object created in two different sessions is hitting database twice or both sessions are referring to same object created in earlier session in memory cache. It should not because L2 cache is disabled by mentioning above

javax.persistence.EntityExistsException with SequenceGenerator

跟風遠走 提交于 2019-12-04 04:59:30
问题 I am inserting some records in Oracle DB. For the uniqueness, I am using SequenceGenerator. Below is the code: public class XxspPoInLineLocqty implements Serializable { @Id @SequenceGenerator(name = "SequenceLocIdGenerator", sequenceName = "LINE_LOCQTY_JPA_ID_SQ") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SequenceLocIdGenerator") @Column(name="LINE_LOCQTY_JPA_ID") private Long lineLocqtyJPAId; //other fields.. } XxspPoInLineLocqty is having @ManyToOne relation with

JPA OneToOne bidirectional .

泄露秘密 提交于 2019-12-04 04:46:11
I have two entity classes that are in @OneToOne relation. The example code are as follow: public class A { @Id private int id; private String name; @JoinColumn(name = "B_ID", referencedColumnName = "id") @OneToOne(cascade=CascadeType.ALL) private B b; //setters and getters } public class B { @Id private int id; private String name; @OneToOne(mappedBy="b") private A a; //setter and getters } my question here is "Can I use setA(A a) method in class B. I mean like this . . em.getTransaction().begin(); A aa = new A(); aa.setId(1); aa.setName("JJ"); em.persist(aa); B bb = new B(); bb.setId(1); bb

JPA criteria query, order on class

我们两清 提交于 2019-12-04 04:12:55
Is there a way with JPA criteria queries to order on class ? Imagine the following domain objects: abstract class Hobby { ... } class Coding extends Hobby { ... } class Gaming extends Hobby { ... } Using regular QL I was able to do from Hobby h order by h.class But when I apply the same logic on a criteria query, the runtime exception "unknown attribute" occurs. CriteriaQuery<Hobby> criteriaQuery = builder.createQuery(Hobby.class); Root<Hobby> hobbyRoot = criteriaQuery.from(Hobby.class); criteriaQuery.orderBy(builder.asc(hobbyRoot.get("class")); List<Hobby> hobbies = entityManager.createQuery

Dedicated cache region for entity subclasses?

≯℡__Kan透↙ 提交于 2019-12-04 03:11:00
We have an extensive entity model with 100+ entity classes. All the entity classes are subclasses of a single entity superclasses. The shared cache mode has been set to ALL . @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "entities") public abstract class LongIdEntity { @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; @Version @Column(name = "OPT_LOCK_VERSION") private Long lockVersion; etc... } An example subclass: @Entity @Table(name = "cars") public class Car extends LongIdEntity { ... } We'd like to cache all entities in the 2nd level cache. The

When using JPA entityManager why do you have to merge before you remove?

旧巷老猫 提交于 2019-12-04 02:48:33
For a while now I have been wondering why when using JPA, do I have to write my delete methods like this: @Transactional public void delete(Account account) { if (entityManager.contains(account)) { entityManager.remove(account); } else { entityManager.remove(entityManager.merge(account)); } } Perhaps the contains isn't needed since the transaction begins and ends with this method, but I still wonder why the remove couldn't just take an unmanaged object. Is it because it needs to be managed in order to know what the id is for that object? Any other insights would be great to hear. I just want

Hibernate entities without underlying tables

巧了我就是萌 提交于 2019-12-04 02:31:34
I have a really ugly legacy database system that I need to integrate with. Essentially I'm doing some read only reporting on the system, and I don't want to set up a thousand entities representing each of the tables that I'm working on. Instead, I'd like to just define an Entity for each of the report-types that I generate (essentially a union of a bunch of columns from different tables), and then let hibernate map from the nasty (many joined, many unioned) sql query to a list of such entities. The question is: can I create an entity that doesn't have an underlying table, and use a sql

Is it possible for a JPA embeddable to contain Embeddable or Collection of Embeddables?

妖精的绣舞 提交于 2019-12-04 02:08:22
I wonder whether it is possible to have an ElementCollection of Embeddable inside another Embeddable ? Here's an example of my Supplier entity which has a list of Addresses, which is of an embeddable type : @Entity public class Supplier extends BaseCommonEntity { @Column(unique=true) private String supplierCode; private String supplierName; @ElementCollection private List<Address> addresses; .... And here's my embeddable Address that contains a list of embeddable Phone @Embeddable public class Address { private String address; private String city; private String country; private String

java.lang.ClassNotFoundException: org.hibernate.engine.transaction.spi.TransactionContext

微笑、不失礼 提交于 2019-12-04 01:03:39
I am developing Spring MVC Hibernate Integration example. In this example I'm using Spring 4.1.9.RELEASE and Hibernate 5.1.0.Final . If I downgrade Hibernate version to 4.3.5.Final then it works. Now inorder to use hibernate 5 what else configuration do I need to change. Please refer more details below. Please find below the exception I see java.lang.ClassNotFoundException: org.hibernate.engine.transaction.spi.TransactionContext at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass