jpa

Get current Spring transaction in JUnit and commit it

梦想的初衷 提交于 2021-01-28 21:44:15
问题 is it possible to get current Spring transaction in JUnit? I want to test JPA in DAO. And DAO do not have transactions. In tests spring create transaction for every method. I want transaction to be commited somewhere in the middle of test. Need it to test DB status. Only solution I found is to create @Rule for every method. 回答1: You can use TestTransaction in order to manage spring test transactions: TestTransaction.flagForCommit(); TestTransaction.end(); This will flag the current

org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(plant)

旧时模样 提交于 2021-01-28 20:03:25
问题 I know this question have been asked several times but, they didn't help me. I have the following test: public class PlantCatalogTests { @Autowired PlantInventoryEntryRepository plantRepo; @Test public void queryPlantCatalog() { assertThat(plantRepo.count(), is(14l)); } and here is PlantInventoryEntryRepository @Repository public interface PlantInventoryEntryRepository extends JpaRepository<PlantInventoryEntry, Long> {} As you see, this repository is based on the class PlantInventoryEntry

Java query with DB Link does not close the Db Link connection

点点圈 提交于 2021-01-28 19:49:47
问题 I have a Java code that connects to Database A. Database A has DB link to Database B. Both database are oracle. I make a JPA connection to Database A Then I run a query from joining a table from DAtabase A to table in Database B Then Close connection to Database A Simple code. I am still seeing the DB link connections on Database B is open. It is not closing. Any idea why? I am assuming that it should be internally handled right? Thoughts? 回答1: If you close a connection to the database all

How to resolve No converter found capable of converting from type TupleBackedMap to type [com.example.dto.ExampleDto]

吃可爱长大的小学妹 提交于 2021-01-28 18:54:57
问题 org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.example.dto.ExampleDto] at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.core.convert.support.GenericConversionService.convert

JPA 2.1 Create entity within JPA EntityListener

你说的曾经没有我的故事 提交于 2021-01-28 14:54:45
问题 I try to create a log entry as soon as one of my entities got changed or created. In order to do this, I registered an EntityListener on an AbstractEntity class. AbstractEntity has a List of LogEntries and the cascade type of this list is ALL (all of my entities inherits from AbstractEntity). Current implementation of my EntityListener: public class EntityChangeListener { @Inject SessionController sessionController; @PreUpdate public void preUpdate(AbstractEntity entity) { createLogEntryFor

WebLogic 12c (12.2.1.4) with Hibernate 5.4

北慕城南 提交于 2021-01-28 14:53:19
问题 I have an application deployed on WebLogic 12c (12.2.1.4) using Hibernate 5.2.18. Weblogic 12c doc references JPA 2.1 compatibility and Hibernate 5.3+ requires JPA 2.2. Can I prepend the JPA 2.2 API to my startup classpath and use Hibernate 5.3+ or should I stick with Hibernate 5.2 for the time being? 回答1: Yes, this configuration is possible. To avoid conflicts with WebLogic built-in JPA capabilities you should do the following: According to this In a full Java EE environment, consider

JPA 2.1 Create entity within JPA EntityListener

百般思念 提交于 2021-01-28 14:42:56
问题 I try to create a log entry as soon as one of my entities got changed or created. In order to do this, I registered an EntityListener on an AbstractEntity class. AbstractEntity has a List of LogEntries and the cascade type of this list is ALL (all of my entities inherits from AbstractEntity). Current implementation of my EntityListener: public class EntityChangeListener { @Inject SessionController sessionController; @PreUpdate public void preUpdate(AbstractEntity entity) { createLogEntryFor

WebLogic 12c (12.2.1.4) with Hibernate 5.4

落爺英雄遲暮 提交于 2021-01-28 14:34:06
问题 I have an application deployed on WebLogic 12c (12.2.1.4) using Hibernate 5.2.18. Weblogic 12c doc references JPA 2.1 compatibility and Hibernate 5.3+ requires JPA 2.2. Can I prepend the JPA 2.2 API to my startup classpath and use Hibernate 5.3+ or should I stick with Hibernate 5.2 for the time being? 回答1: Yes, this configuration is possible. To avoid conflicts with WebLogic built-in JPA capabilities you should do the following: According to this In a full Java EE environment, consider

How to represent and query from a three entity relationship in spring boot?

不想你离开。 提交于 2021-01-28 13:33:38
问题 I am developing a mall system where a User can have one or more shops. If you create a shop, you have the role ADMIN for that shop, else: you create an account then you are assigned a shop as a MANAGER by the ADMIN of that shop. A user can have a shop that they are an admin , but as well be a manager to a different shop assigned to you by an owner of a that shop. Thus, i have come up with three entities: User, Role and Shop. User Entity @Entity @Table(name = "us_users") public class User {

How to represent and query from a three entity relationship in spring boot?

假如想象 提交于 2021-01-28 13:32:51
问题 I am developing a mall system where a User can have one or more shops. If you create a shop, you have the role ADMIN for that shop, else: you create an account then you are assigned a shop as a MANAGER by the ADMIN of that shop. A user can have a shop that they are an admin , but as well be a manager to a different shop assigned to you by an owner of a that shop. Thus, i have come up with three entities: User, Role and Shop. User Entity @Entity @Table(name = "us_users") public class User {