hibernate

java 面试题

纵然是瞬间 提交于 2021-02-10 02:44:02
1.hashmap、concurrenthashmap底层实现和区别 hashmap是基于数组+ 链表结构的,数组下标有hash生成,链表主要是为了防止hash冲突,即使两个对象的hashCode一样,它们会放到当前数组索引位置的链表中,Java8后链表长度大于8就会转为红黑树, 主要是为了提高查找效率,链表查找慢,增删改快 区别:hashmap是线程不安全的,ConcurrentHashMap是线程安全的,把数据分成了不同的段,使用的分段锁技术,通过hash计算那些数据放在那个段中,查找也是如此 2.spring框架的原理 spring框架主要是用来创建、注册、配置、管理、维护bean的容器,主要是利用Java反射技术动态维护、调用对象,主要包括控制反转(IOC)以及面向切面(AOP),三种注入方式分别是Field注入 (使用@Autowired或@Resource注入)、构造器注入和Setter方法注入 3.如何写一个orm框架 对象-关系映射(Object-Relational Mapping,简称ORM),处理对象与数据库交互的,常见的有hibernate、jpa、ibatis等 4.hibernate一级缓存和二级缓存,hibernate其他缓存 hibernate缓存分为三种:一级缓存,二级缓存和查询缓存, session内的缓存即一级缓存,不能被清除

Java开发面试题,3年工作经验的Java程序员面试经

无人久伴 提交于 2021-02-09 20:31:43
一、Java基础部分 1、使用length属性获取数组长度,public、private、protected、friendly区别 2、Collection和Collections区别 3、String s=new String(‘xyz’);创建了几个object对象 4、short s1; s1=s1+1;是否有错? 5、Overriding和Overloading区别 6、Set里面的元素不能重复,用什么方法区分重复与否。 7、给出一个常见的runtime exception。 8、error和exception区别。 9、List和Set是否继承自Collection接口。 10、abstract class和interface 的区别。 11、是否可以继承String类。 12、try{}里有一个return语句,紧跟在try后的finally里的code会不会被执行,什么时候执行,return前执行还是return后执行。 13、最有效率的方法算2*8等于几 14、两个对象值相同,x.equal(y)==true,但是却可有不同的hashcode,这句话对不对。 15、值传递和引用传递 16、switch是否作用在byte、long、string上。 17、ArrayList和Vector区别,HashMap和Hashtable区别(了解这几个类的底层jdk中的编码方式

Spring first request very slow

孤街浪徒 提交于 2021-02-09 11:48:36
问题 I have application in Spring Boot. After initialization of Spring Boot with embeded tomcat, the first response is very slow. How can I fix it? Has spring boot any warmup command/mode? I am thinking too about connection with database and I am wondering about connection database, probably spring connects with Postgres during first request. 回答1: You could either use ApplicationRunner or CommandlineRunner to run something on startup: https://docs.spring.io/spring-boot/docs/current/reference

Switch from JsonStringType to JsonBinaryType when the project uses both MySQL and PostgreSQL

青春壹個敷衍的年華 提交于 2021-02-09 08:26:09
问题 I have a problem with column json when it's necessary to switching from PostgreSQL to MariaDB/MySql. I use Spring Boot + JPA + Hibernate + hibernate-types-52. The table i want to map is like this: CREATE TABLE atable( ... acolumn JSON, ... ); Ok it works for PostgreSQL and MariaDB/MySql. The problem is when i want to deploy an application that switch easly from one to another because the correct hibernate-types-52 implementation for PostgreSQL and MySQL/MariaDB are different This works on

Maven Aspectj plugin calls the JPA model generator again

主宰稳场 提交于 2021-02-08 14:00:08
问题 I have a Maven project where I generate the JPA metamodel using the Hibernate metamodel generator. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>xxx</groupId> <artifactId>xxx</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <artifactId>xxx</artifactId> <dependencies>

Springframework.dao.InvalidDataAccessResourceUsageException hibernate.SQLGrammarException MySQLSyntaxErrorException

笑着哭i 提交于 2021-02-08 12:57:18
问题 I'm breaking my head trying to find out what's wrong here. I'm working on a schema: It has a Story entity (table: stories) and I'm trying to add a column to this stories.portofoliotype_id which is a foreign key to PortfolioType (table: portofoliotypes) . I think I have the annotations right, I even logged MySQL queries, it gets the following query, which is correct. I'm trying to create a new story: insert into stories(backlog_id, description, iteration_id, name, parent_id,portfoliotype_id,

Hibernate exception. QuerySyntaxException: unexpected token: HAVING

为君一笑 提交于 2021-02-08 11:24:20
问题 I try use this HQL query: Result.find("SELECT c, ( 3959 * acos( cos( radians(?) ) * "+ "cos( radians( c.latitude ) ) *"+ "cos( radians( c.longitude ) - radians(?) ) +"+ "sin( radians(?) ) * sin( radians( c.latitude ) ) ) ) " + "AS distance FROM City c HAVING distance < ? ORDER BY distance ASC", latitude, longitude, latitude, radius).fetch(); But in result: IllegalArgumentException occured : org.hibernate.hql.ast.QuerySyntaxException: unexpected token: HAVING near line 1, column 204 [SELECT c,

HQL query to select data between two dates not returning any record

落爺英雄遲暮 提交于 2021-02-08 11:22:49
问题 ReportView I'm getting values of Dates from JavaFX DatePicker objects tDateFrom, tDateTo. I've tried, (1) List list = session.createQuery("from ReportView where date between :stDate and :edDate") .setTimestamp("stDate", Date.from(Instant.from(tDateFrom.getValue().atStartOfDay(ZoneId.systemDefault())))) .setTimestamp("edDate", Date.from(Instant.from(tDateTo.getValue().atStartOfDay(ZoneId.systemDefault())))) .list(); (2) SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

HQL query to select data between two dates not returning any record

两盒软妹~` 提交于 2021-02-08 11:21:38
问题 ReportView I'm getting values of Dates from JavaFX DatePicker objects tDateFrom, tDateTo. I've tried, (1) List list = session.createQuery("from ReportView where date between :stDate and :edDate") .setTimestamp("stDate", Date.from(Instant.from(tDateFrom.getValue().atStartOfDay(ZoneId.systemDefault())))) .setTimestamp("edDate", Date.from(Instant.from(tDateTo.getValue().atStartOfDay(ZoneId.systemDefault())))) .list(); (2) SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Error creating transaction manager bean

空扰寡人 提交于 2021-02-08 10:29:38
问题 Hi Im creating a sample project for springMVc with hibernate with oracle as backend . I am stuck with one issue seems like some configuration issue but unable to identify whats wrong. Any guidance will be of great help. org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource] The stacktrace: WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error