jpa-2.0

Setting JPA persistence properties dynamically

妖精的绣舞 提交于 2019-12-08 15:27:15
问题 Let's say I have the following persistence.xml with the connection url, user & password all hard-coded. The following is for Hibernate 3.2. For Hibernate 3.5 ++, we have to change "hibernate.connection" to "javax.persistence". But let me ask this question regardless of the literals "hibernate.connection" or "javax.persistence". <persistence-unit name="obamacare" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <exclude-unlisted-classes>false<

Best way to initialize JpaPersistModule

风格不统一 提交于 2019-12-08 11:20:28
问题 I use com.google.inject.persist.jpa.JpaPersistModule in my application. The configuration is located in persistence.xml file, but some of the properties are dynamic and I don't want store them in this file (for example javax.persistence.jdbc.url etc) but rather inject them from some other source. I know that there's a JpaPersistModule.properties(java.util.Properties p) method that allows to do exactly what I need. The problem is that I don't see a good way to pass that java.util.Properties

JPA EntityManager with Hibernate - find and remove does not delete data from database

穿精又带淫゛_ 提交于 2019-12-08 08:57:11
问题 Having trouble getting the following code to work... I've got a JpaTransactionManager txManager autowired into this test. I know record with ID 39 does exist. It still exists at the end of the transactions, too... TransactionStatus status = txManager.getTransaction(def); A a = mock(A.class); when(a.getId()).thenReturn(Long.valueOf(39)); sut.delete(a); txManager.commit(status); status = txManager.getTransaction(def); a = sut.get(a.getId()); txManager.commit(status); assertNull(a); Code in

hibernate update vs JPA merge on detached instance

南笙酒味 提交于 2019-12-08 08:15:53
问题 Both will update the persistent state but merge will return attached instance letting the given one unchanged. update will attach the given instance my question is so : will JPA merge also trigger a select (i suppose it will to get the attached instance) whereas hibernate update won't ? please don't try to explain me things that can already be found here What are the differences between the different saving methods in Hibernate? 来源: https://stackoverflow.com/questions/22459233/hibernate

How to use a native db operator (postgres ~ ) with JPA criteria builder?

谁说我不能喝 提交于 2019-12-08 08:09:50
问题 I am using JPA 2.0 criteria to build the following query (simplified): select n from notif n where n.message ~ 'b.*la' I am using postgresql db, and I really need the ~ operator,not like. Is there something equivalent to the CriteriaBuilder.function I can use? Alternatively, is there a function form of the ~ operator in postgres so I can use the mentioned cb.function method. I have only found the postgresql regexp_matches function, but it returns an array of matches not a boolean. Solution:

glassfish and h2database problem

牧云@^-^@ 提交于 2019-12-08 07:40:42
问题 I build an java based app. using hibernate JPA, spring and h2database. I using h2database in memory mode, here is the jdbc properties: jdbc.url=jdbc\:h2\:mem\:test_db;DB_CLOSE_DELAY\=-1 jdbc.driverClassName=org.h2.Driver jdbc.username=sa jdbc.password= This values I'm using in dataSource.xml like this: <bean id="basicDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value

How does a JPA provider access (private) field values when no getter/setter method are defined?

女生的网名这么多〃 提交于 2019-12-08 07:39:15
问题 As entity class field can be mark as private when @Entity access mode is " Field " access , just wanted to understand how provider will able to access entity state in this case as fields are marked as Private and will not be visible outside class ? Edit #1 - As you know , for field access , getter and setter method are optional. So I wanted to understand how provider will access the field when no getter/setter method are provided. Hope this clarify my question . 回答1: Referring to the official

Convert Oracle Case Statement to JPQL or JPA repository query?

半城伤御伤魂 提交于 2019-12-08 07:14:49
问题 I am new to the JPA2.0 world, but I hope case statements can also be mapped to JPQL or using JPARepository . I am using Oracle 12c. How to convert below statement to JPQL to repository query? select case when exists (select 1 from ABC_OWNER.BANK_ACCT where ACC_NUM = ?) then 'Y' else 'N' end from dual; 来源: https://stackoverflow.com/questions/51565156/convert-oracle-case-statement-to-jpql-or-jpa-repository-query

Retrieve information from JPA Metamodel

天大地大妈咪最大 提交于 2019-12-08 05:28:40
问题 Jpa 2 metamodel has one known use: type safe criteria query. My question is different: I suppose metamodel can be source of information like length, human friendly description, left-right alligment etc, for example for building pretty GUI table (desktop or web, no matter). I imagine such quasi code: SomeTable st = buildTable(Person_.class, Person_.surName, Person_.Height) Tell me, I'm thinking in wrong way? My google research give no result. Or give some info to start reading EDIT: auto

Transaction and Rollback in Spring with JPA

醉酒当歌 提交于 2019-12-08 04:58:42
问题 Hi friends of StackOverflow, I do not understand how to roll back I read the documentation of Spring, but I still do not understand. Basically I'm going to persist an object in the db (with primary key manually) all the way here all right, the object is inserted into the db. But when you persist the object again with the same primary key I have caused an exception, and rightly so, a violation of restriction of uniqueness. In this case I would get a Transaction rollback and warn you that there