hibernate

SEVERE: Exception looking up UserDatabase under key UserDatabase javax.naming.NameNotFoundException: Name [UserDatabase] is not bound in this Context

孤街浪徒 提交于 2021-02-11 09:52:06
问题 im using TOMCAT 9 and latest hibernat jars with java 1.8 i create simple user in mysql and 1 table db called foo1 in my webapp in tomcat i configured based on examples online : workspace\HibernateApp\src\hibernate.cfg.xml: <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="show_sql">true<

SEVERE: Exception looking up UserDatabase under key UserDatabase javax.naming.NameNotFoundException: Name [UserDatabase] is not bound in this Context

半腔热情 提交于 2021-02-11 09:51:32
问题 im using TOMCAT 9 and latest hibernat jars with java 1.8 i create simple user in mysql and 1 table db called foo1 in my webapp in tomcat i configured based on examples online : workspace\HibernateApp\src\hibernate.cfg.xml: <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="show_sql">true<

Entity not returned from L1 cache

余生颓废 提交于 2021-02-11 07:19:45
问题 We are using Spring JPA in our project without any L2 cache. As per the docs, within a session, the related entities are returned from the L1 cache. To test this out, in application.yml I enabled the query generation spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true In the implementation class, I added the following two lines of code. Employee emp1 = employeeRepository.getByEmployeeCode(empCode); Employee emp2 = employeeRepository.getByEmployeeCode(empCode); I was

Cannot catch DataIntegrityViolationException

青春壹個敷衍的年華 提交于 2021-02-11 06:49:28
问题 I am using Spring Boot 2 with spring-boot-starter-data-jpa with an underlying MariaDB. I have table with a unique key "username". I want to catch DataIntegrityViolationException if this constraint is violated, but it seems like Spring is logging DataIntegrityViolationException and does not rethrow the after logging(my best guess). MySQLIntegrityConstraintViolationException is thrown instead. I would like to catch DataIntegrityViolationException in UserService.createUser(..) . Here are a

Cannot catch DataIntegrityViolationException

邮差的信 提交于 2021-02-11 06:48:12
问题 I am using Spring Boot 2 with spring-boot-starter-data-jpa with an underlying MariaDB. I have table with a unique key "username". I want to catch DataIntegrityViolationException if this constraint is violated, but it seems like Spring is logging DataIntegrityViolationException and does not rethrow the after logging(my best guess). MySQLIntegrityConstraintViolationException is thrown instead. I would like to catch DataIntegrityViolationException in UserService.createUser(..) . Here are a

Spring boot JPA no returning existing result using findById

心不动则不痛 提交于 2021-02-11 02:45:31
问题 I have created a pretty small and simple Spring Boot app using the Oracle database and some JPA queries. This is the code snippet which is not returning data, which is actually exists in database. letterRecipientNonOas = letterRecipientNonOasRepository .findById(Long.valueOf(letterRecipientDTO.getNonOas().getId())) .orElseThrow(() -> new EntityNotFoundException(LetterRecipientNonOas.class, Constant.MESSAGE_ENTITY_NOT_FOUND)); here findById is returning empty result set. this is my repository

JPA (Hibernate) + Spring: Dealing with unique constraint violations

大憨熊 提交于 2021-02-10 20:26:21
问题 I have a entity A with a unique field and that field basically defines the entity, meaning it it is equal then then entity is also exactly the same. A second point is that it is lets say in no way exceptional if that constraint is violated. Meaning it is fully expected that users will try to input duplicates. In case of duplicate, the application should silently chose the already existing entity. My question is now what I should do especially when saving entities containing a list of As. just

How to mock EntityManager

谁都会走 提交于 2021-02-10 20:15:51
问题 I first posted a question on here about a Unit test, EntityManager and NullPointerException. And then somebody advised me to look up mocking, so I did. However, I am still facing the same issues. I like to know if I am missing something? Is there a setup I forgot to add? Do I require to indicate the location of the persistence XML file? I would appreciate any help with that. I looked at other similar questions. However, I didn’t have much luck. 1./ How to mock object in EntityManager? 2./ How

H2 Database Json Field Hibernate Converter Exception

随声附和 提交于 2021-02-10 20:11:55
问题 I just try to insert a json value in h2. Then I want to get back this json value as object with hibernate converter. But the error looks like below: My insert query is: INSERT INTO log( id, activities, date) VALUES (1, '[{"actionType": "EMAIL"}]', '2019-12-10 00:00:00'); When I try to get back this field with hibernate converter, field comes with quotation mark: "[{"actionType": "EMAIL"}]" But it should be: [{"actionType": "EMAIL"}] org.springframework.dao.InvalidDataAccessApiUsageException:

NullPointerException while trying to add an orm layer using hibernate

可紊 提交于 2021-02-10 15:17:47
问题 Well,I have been trying to add an orm layer for past 3 weeks and i havent been able to do so.I was trying to learn from the tutorial.I have done whatever the tutorial says .Here is the code Student.java package com.codinghazard.actions; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="student") public class Student { @Id @GeneratedValue private int id;