hibernate

Hibernate OnDelete cascade in test doesn't work

一笑奈何 提交于 2020-08-26 08:47:05
问题 I have one-directional related entities: @Entity public class Book { private String isbn; } @Entity private class Recommentation { @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "book_id", nullable = false) @OnDelete(action = OnDeleteAction.CASCADE) private Book book; } And the following test: @RunWith(SpringRunner.class) @DataJpaTest public class BookRepositoryTest { @Autowired private TestEntityManager testEntityManager; @Autowired private BookRepository

Changes made in a @Transactional method are not reflected to the Entity

懵懂的女人 提交于 2020-08-26 08:33:49
问题 I have the following method in my Service Layer, which Retrieves an entity by ID Executes an update to the entity Retrieves and returns the same entity @Transactional @Override public Order acceptOrder(long orderId){ Order Order = getOrderById(orderId); // 1 orderDao.updateOrderStatus(OrderStatus.PENDING_COMPLETION, orderId); // 2 return getOrderById(orderId); // 3 } The service's method getOrderById @Override public Order getOrderById(long id) { return orderDao.get(Order.class, id); } And

Unable to add child entity - JPA OneToMany relationship

久未见 提交于 2020-08-26 08:30:13
问题 I have been trying to add an entity to database that entity have OneToMany relationship to another entity but when I insert that entity it is saying unable to insert id because it is null. I have mapped parent child class like this: @OneToMany(mappedBy = "directory", cascade = CascadeType.ALL) private List<DirectoryRemarksEntity> remarks; Child Entity : @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "DIRECTORY_ID") @JsonIgnore private DirectoryTableEntity directory; My json looks like

Transaction cannot proceed STATUS_MARKED_ROLLBACK when running on jboss standalone

£可爱£侵袭症+ 提交于 2020-08-24 07:24:46
问题 Does anyone experience the following issue? I'm able to successfully build, deploy and run my javaee6 application in jboss inside eclipse using jboss tools. But when we deployed it on another server running on standalone we got an error. I tried it the same machine where eclipse is and run on jboss as standalone and got the same error. See error below, I've removed some parts. 06:53:46,423 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-/127.0.0.1:8080-1) Transaction cannot

Transaction cannot proceed STATUS_MARKED_ROLLBACK when running on jboss standalone

北慕城南 提交于 2020-08-24 07:24:27
问题 Does anyone experience the following issue? I'm able to successfully build, deploy and run my javaee6 application in jboss inside eclipse using jboss tools. But when we deployed it on another server running on standalone we got an error. I tried it the same machine where eclipse is and run on jboss as standalone and got the same error. See error below, I've removed some parts. 06:53:46,423 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-/127.0.0.1:8080-1) Transaction cannot

JPA inheritance @EntityGraph include optional associations of subclasses

不想你离开。 提交于 2020-08-24 05:13:09
问题 Given the following domain model, I want to load all Answer s including their Value s and their respective sub-children and put it in an AnswerDTO to then convert to JSON. I have a working solution but it suffers from the N+1 problem that I want to get rid of by using an ad-hoc @EntityGraph . All associations are configured LAZY . @Query("SELECT a FROM Answer a") @EntityGraph(attributePaths = {"value"}) public List<Answer> findAll(); Using an ad-hoc @EntityGraph on the Repository method I can